#include using namespace std; bool coprime(long long a, long long b) { bool c = true; for (long long i = 2; i <= a/2; i++) { if (a%i==0 && b%i==0) { c = false; break; } } return c; } int main() { long long a, b, m = 0; cin >> a >> b; for (long long i = b; i - a > m; i--) { for (long long j = a; j < b - m; j++) { if (coprime(j, i)) { m = i - j; break; } } } if (m == 0) { cout << "-1" << endl; } else { cout << m + 1 << endl; } return 0; }