#include <iostream>
#include <string>
using namespace std;
int main()
{
int up,down,step=0,highest=0;
while(cin>>up>>down)
{
do
{
step+=up;
if(step>highest)
{
highest=step;
}
step%=down;
}while(step!=0);
cout<<highest<<endl;
}
//system("pause");
return 0;
}