#include #include #include #include using namespace std; int main() { int n,m; int t; while(scanf("%d%d",&n,&m)!=EOF) { t=(m%n)-1; if(t<0) t=n-1; printf("%d\n",t); } return 0; }