#include int main() { int a, b; scanf("%d %d", &a, &b); int i; for (i = 1;; i++) { if (i % a == b % i) { printf("%d\n", i); return 0; } } return 0; }