#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N > M) swap(N, M);
    while (1) {
      if (N <= 2 || M % (N - 1) == 1) {
        cout << max(2, N) << endl;
        break;
      }
      M %= N - 1;
      swap(N, M);
    }
  }
  return 0;
}
