#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <queue>

#define LL long long
#define pb push_back
#define lm 100001
#define MOD 1000000007


using namespace std;
LL Euc(LL x, LL y)
{
    if(!y)
        return x;
    return Euc(y,x%y);
}
LL int a,b;
int main()
{

    //freopen("data.txt", "r", stdin);

    cin>>a>>b;
    LL res=-1,c;

    while(b-a>res)
        {
            c=a;
            while(b-c>res)
            {
                if(Euc(c,b)==1)
                {
                    res=max(res,b-c+1);
                }
                c++;
            }
            b--;
        }
    cout<<res;
    return 0;
}