#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, ans;
void check1() {
  for (int i = 1; i <= min(n + m, N); i++) {
    int nr = n / i, nl = (n + i) / (i + 1);
    int mr = m / i, ml = (m + i) / (i + 1);
    if (nr >= nl && mr >= ml) {
      ans += nr - nl + mr - ml + 1;
      if (n % (i + 1) == 0 && m % (i + 1) == 0) ans--;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, j; i <= min(n, m); i = j + 1) {
    j = min(n / (n / i), m / (m / i));
    int nr = n / j, nl = (n + j) / (j + 1);
    int mr = m / j, ml = (m + j) / (j + 1);
    if (nr >= nl && mr >= ml) {
      ans += nr - nl + mr - ml + 1;
      if (n % (j + 1) == 0 && m % (j + 1) == 0) ans--;
    }
  }
  printf("%d\n", ans);
}
