#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 16005
#define MOD 1000000007

using namespace std;
LL Euclid(LL a,LL b)
{
    if(!b)
        return a;
    return Euclid(b,a%b);
}
LL n,m,x,y;
int c,res;
int main()
{

    //freopen("data.txt", "r", stdin);
    scanf("%d%d",&n,&m);
    if(n<m)
        swap(n,m);
    y=Euclid(n,m);
    x=m*(n/y);
    while(n<x)
    {
        n++;
        m++;
        c++;
        y=Euclid(n,m);
        if(x>(m*(n/y)))
        {
            x=m*(n/y);
            res=c;
        }
    }
    cout<<res;
    return 0;
}