N,K = map(int,input().split()) N_list = [False for x in range(N)] #print(N_list) k = K while abs(k) <= K : #print(k) N_list[k%N] = True k -= 2 print(sum(N_list))