#include using namespace std; #define ll long long #define pb push_back #define mp make_pair #define pii pair #define pll pair #define all(x) (x).begin(), (x).end() #define fi first #define se second ll a, b; int main() { cin.sync_with_stdio(false); // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); cin >> a >> b; if (__gcd(a, b) == 1) { cout << b - a + 1; return 0; } if (a + 1 <= b && __gcd(a + 1, b) == 1) { cout << b - a; return 0; } if (a <= b - 1 && __gcd(a, b - 1) == 1) { cout << b - a; return 0; } if (a + 1 <= b - 1 && __gcd(a + 1, b - 1) == 1) { cout << b - a - 1; return 0; } cout << -1; return 0; }