#include <iostream>
using namespace std;

long long int x, y;
long long int s;

long long int gcd(long long int a, long long int b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int main() {
    cin >> x >> y;
    if (x == 1) {
        cout << y - x + 1;
        return 0;
    }
    s = -1;
    for (long long int i = y - x; i >= 1 && s == -1; i--)
        for (long long int j = x; j <= y - i && s == -1; j++) {
            if (gcd(j, j + i) == 1) s = i + 1;

    }
    cout << s;
    return 0;
}