#include <iostream>
using namespace std;
int main(void) {
    int a, b;
    cin >> a >> b;
    int bp = b - a;
    int p = bp;
    int d = a % p ? p - a % p : 0;
    while (d + p > bp) {
        p--;
        d = a % p ? p - a % p : 0;
    }
    cout << p << endl;
}
#include<bits/stdc++.h>
using namespace std;

#define endl		'\n'
#define w(t)		int t;cin>>t;while(t--)
#define int			long long
#define fr(i,a,b)	for(int i=a;i<=b;i++)
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define pb 			push_back
#define ppb			pop_back
#define mp			make_pair
#define all(x)		x.begin(),x.end()
#define ff			first
#define ss			second
#define pii			pair<int,int>
#define vi			vector<int>
#define vvi			vector<vi>
#define pqi			priority_queue<int>
#define pqd			priority_queue<int,vi,greater<int>>
#define inf			1e18
#define mod			1000000007
#define PI 			3.14159265358979323846264338327950288419716939937510


int32_t main() {

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int a,b;
	cin>>a>>b;
	int ans=-1;
	fr(i,1,b){
		int x=(b/i)*i;
		int y=((b/i)-1)*i;

		if(y>=a && y<x){
			ans=i;
		}
	}

	cout<<ans<<endl;


	return 0;
}