#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=0,c;
    if(a==b)
        cout<<-1;
    else{
        if(Euc(a,b)==1)
        {
            cout<<b-a+1;
            return 0;
        }
        b--;
        while(b-a>res)
        {
            c=a;
            while(b-c>res)
            {
                if(Euc(c,b)==1)
                {
                    res=max(res,b-c);
                }
                c++;
            }
            b--;
        }

        if(res)
            cout<<res;
        else
            cout<<-1;
    }
    return 0;
}