#include <iostream>
using namespace std;
int euclid(int a, int b)
{
    int c;
    while (b) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main()
{
    int a, b ,n = 1;
    bool found = false;
    cin>>a>>b;
    while(!found)
    {
        if(euclid(a+n,b+n)!=1)
            found = true;
        n++;
    }
    cout<<n-1;
    return 0;
}