#include <bits/stdc++.h>
using namespace std;
int n, m;
void swap(int &x, int &y) {
  int a = y;
  y = x;
  x = a;
}
int gcd(int x, int y) {
  if (y == 0) return x;
  if (x < y) swap(x, y);
  return gcd(y, x % y);
}
int main() {
  cin >> n >> m;
  cout << gcd(n - 1, m - 1) + 1 << endl;
  return 0;
}
