#include using namespace std; int main() { long n, nn, d, dd, a, b; cin >> n >> d; nn = n; dd = d; while (1){ a = n % d; if (a == 0) break; n = d; d = a; } b = nn * dd / d / dd - 1; cout << b << endl; return 0; }