#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("mod.in");
ofstream fout("mod.out");
int a, b, c = 1, x, y, gbd, gcd(int, int);
#define cin fin
#define cout fout
main()
{
cin >> a >> b;
gbd = a / gcd(a, b) * b;
x = (x + b) % b;
cout << x;
}
int gcd(int a, int b)
{
if (b == 0){
y = 0;
x = c / a;
return a;
}
int g = gcd(b, a % b), xx, yy;
xx = y;
yy = x - y * (a / b);
x = xx;
y = yy;
return g;
}