#include <bits/stdc++.h>
using namespace std;
long n;
long m;
long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
int main() {
  cin >> n >> m;
  cout << gcd(n - 1, m - 1) + 1;
  return 0;
}
