#include <bits/stdc++.h>
using namespace std;
int measure(int x, int y) {
  int z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans = measure(n - 1, m - 1) + 1;
  cout << ans << endl;
  return 0;
}
