p,k = map(int,input().split())
ans = 0
for i in range(p):
    if i%p == k:
        ans += 1
print(ans)