#include using namespace std; #define dbg(x) (cout<<#x<<" = "<<(x)<<'\n') typedef long long int lld; const int INF = (1LL << 30) - 1; const lld LINF = (1LL << 62) - 1; lld A, B, sol = 1; int main() { cin.sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif scanf("%lld%lld", &A, &B); if (A == 1) return 0 * printf("%lld\n", B - A); if (A == B) return 0 * printf("-1\n"); for (lld i = A; i <= min(A + 5000, B); i++) for (lld j = B; j >= max(A, B - 5000); j--) if (__gcd(i, j) == 1) sol = max(sol, j - i); printf("%lld\n", sol); return 0; }