#include int main(void){ int A,B; int x; scanf("%d",&A); scanf("%d",&B); for(x = 1; x < 100000; x++){ if(x % A == B % x){ break; } } printf("%d\n",x); }