A, B = map(int, input().split()) for x in range(1, 10000): if x % A == B % x: print(x) exit(0)