N,K = map(int,input().split()) N_list = [False for x in range(N)] #print(N_list) #N_list[0] = True for i in range(1<>j)&1 == 1: K_list[j] = 1 for k in K_list: n += k ans = n % N N_list[ans] = True #print(K_list) print(sum(N_list))