#include <bits/stdc++.h>
using namespace std;
long long a, b;
inline pair<long long, long long> cal(long long l, long long r) {
  long long R = a;
  if (l) R = a / l;
  return make_pair((a + r - 1) / r, R);
}
long long cul(long long pl, long long pr, long long l, long long r) {
  assert(l >= pl);
  assert(r >= pr);
  assert(l <= r);
  l = max(pr + 1, l);
  return max(r - l + 1, 0LL);
}
int main() {
  scanf("%lld%lld", &a, &b);
  if (b > a) swap(a, b);
  if (b == 0) {
    puts("1");
    return 0;
  }
  long long ans = 0;
  long long pl = 0, pr = 0;
  for (int l = 1, r; l <= b; l = r + 1) {
    pair<long long, long long> x;
    r = b / (b / l) - 1;
    if (r >= l) {
      assert(b % r != 0);
      x = cal(b / r, (b + r - 1) / r);
      if (x.second >= x.first) {
        ans += cul(pl, pr, x.first + l, x.second + r);
        pl = x.first + l;
        pr = x.second + r;
      }
    }
    r++;
    int tl, tr;
    if (b % r == 0)
      tl = b / r - 1, tr = b / r + 1;
    else
      tl = b / r, tr = (b + r - 1) / r;
    x = cal(tl, tr);
    if (x.second >= x.first) {
      ans += cul(pl, pr, x.first + r, x.second + r);
      pl = x.first + r;
      pr = x.second + r;
    }
  }
  printf("%lld", ans);
  return 0;
}
