#include #include #include using namespace std; #define ll long long ll x[1005], y[1005]; bool prime (ll x) { if(x == 0) return 0; if(x == 1) return 0; if(x % 2 == 0 && x != 2) return 0; int d, lim = sqrt(x); for(d = 3; d <= lim; d += 2) if(x % d == 0) return 0; return 1; } ll gcd (ll a, ll b) { if(b == 0) return a; return gcd(b, a %b); } int main() { ll a, b, i, j, ans; scanf("%lld%lld", &a, &b); ans = -1; for(i = a; i < a + 25000 && i <= b; ++ i) for(j = b; j > b - 25000 && j >= a && j >= i; -- j) if(gcd(i, j) == 1 ) ans = max(ans, j - i + 1); printf("%d\n", ans); return 0; }