#include int n, m; int main() { while (scanf("%d%d", &n, &m) == 2) printf("%d\n", (m - 1) % n); return 0; }