#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int n, m, ans;
bool ok;
int main() {
  while (scanf("%d%d", &n, &m) >= 1) {
    if (n > m) swap(n, m);
    while (m - (n - 1) >= n) m -= n - 1;
    int t = m - n;
    if (t == 0 || t == n - 1) {
      printf("%d\n", n);
      continue;
    }
    ok = false;
    ans = 0;
    for (int d = 2; d < n - 1; d++) {
      if ((n - 1) % d == 0 && t % d == 0) {
        ok = true;
        int p = (n - 1) / d;
        ans = max(ans, (n + p - 1) / p);
      }
    }
    printf("%d\n", ok ? ans : 2);
  }
  return 0;
}
