import sys def gcd(a, b): while b: a, b = b, a%b return a lower = long(sys.stdin.readline().strip()) upper = long(sys.stdin.readline().strip()) i = lower j = upper found = False for i in range(lower, upper): for j in range(upper, lower, -1): if i % 2 == 1 or j % 2 == 1: res = gcd(i, j) if res == 1: print j - i + 1 found = True break if found: break if i >= j: print -1