#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

template <class T>
void chmax(T& a, T b) {
    a = max(a,b);
}

template <class T>
void chmin(T& a, T b) {
    a = min(a,b);
}

#define rep(i, a, b) for (ll i = a; i < b; i++)
#define all(container) container.begin(), container.end()

typedef long l;
typedef long long ll;
typedef pair<int, int> ipi;
typedef pair<ll, ll> lpl;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

#define MOD 1'000'000'007LL
ll LLINF = LLONG_MAX / 2;

int main() {
    ll A, B;
    cin >> A >> B;
    for (int i=B-A;i > 0;i--) {
        if ( ceil(double(A)/i) != B/i) {
            cout << i;
            return 0;
        }
    }
    return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;


#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };

const ll INF = 100000000000000;


int main() {
    int a, b;
    cin >> a >> b;
    int yaku = b - a;
    for (int i = yaku; i >= 1; i--) {
        if (a % i == 0) {
            yaku = i;
            break;
        }
        if (a + (i - a % i) + i <= b) {
            yaku = i;
            break;
        }
    }
    cout << yaku << endl;

    return 0;
}