#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll p, n;
unordered_set<ll> marked;
marked.insert(0);
cin >> p >> n;
ll sum = 0;
for(int i = 1; i <= min(p * 2, n); i++) {
sum = (sum + i) % p;
marked.insert(sum);
}
cout << marked.size() << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglsbCBwLCBuOwoJdW5vcmRlcmVkX3NldDxsbD4gbWFya2VkOwoJbWFya2VkLmluc2VydCgwKTsKCgljaW4gPj4gcCA+PiBuOwoKCWxsIHN1bSA9IDA7Cglmb3IoaW50IGkgPSAxOyBpIDw9IG1pbihwICogMiwgbik7IGkrKykgewoJCXN1bSA9IChzdW0gKyBpKSAlIHA7CgkJbWFya2VkLmluc2VydChzdW0pOwoJfQoKCWNvdXQgPDwgbWFya2VkLnNpemUoKSA8PCBlbmRsOwoKCXJldHVybiAwOwp9