using namespace std;
const int N = 1000003, null = INT64_MAX;
typedef long long ll;
ll m,x,y;
bool f[N];
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1;y=0;
return a;
}
ll d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
int main() {
int a,b;
cin>>a>>b;
ll d= exgcd(a,b,x,y);
cout<<x+b/d*1;
}
求解ax+by=c;