#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int res = (n*m) / __gcd(n,m);
cout<<res - (n+m)<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int res = (n*m) / __gcd(n,m);
cout<<res - (n+m)<<endl;
return 0;
}