// Slower C++ solution:
/**

 *    author:  tourist

 *    created: 05.01.2020 11:08:10       

**/

#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



ll solve(ll n, ll a, ll b, ll m) {

  if (b == 0) return n * (a / m);

  if (a >= m) return n * (a / m) + solve(n, a % m, b, m);

  if (b >= m) return n * (n - 1) / 2 * (b / m) + solve(n, a, b % m, m);

  return solve((a + b * n) / m, (a + b * n) % m, m, b);

}



pair<long long, long long> GetKBest(int k, long long cx, long long cy) {

  long long high = (long long) sqrt(2 * k * (double) cx * (double) cy);

  long long low = max(0LL, high - cx - cy - 1);

  while (low < high) {

    long long mid = (low + high) >> 1;

    long long cnt = solve(mid / cx + 1, mid % cx, cx, cy) + (mid / cx + 1);

    if (cnt >= k) {

      high = mid;

    } else {

      low = mid + 1;

    }

  }

  long long sx = 0, sy = 0;

  for (int x = 0; x * cx <= high; x++) {

    long long cc = (high - x * cx) / cy + 1;

    sx += cc * x;

    sy += cc * (cc - 1) / 2;

  }

  return {sx, sy};

}



bool Solvable(int k, int X, int Y) {

  auto a = make_pair(-1LL, -1LL), b = a;

  long long total = (long long) 1e9 + 7;

  long long low = 0, high = total;

  while (low < high) {

    long long mid = (low + high) >> 1;

    auto p = GetKBest(k, total - mid, mid);

    if (p.first <= X && p.second <= Y) {

      return true;

    }

    if (p.first >= X && p.second >= Y) {

      return false;

    }

    if (p.first < X) {

      a = p;

      low = mid + 1;

    } else {

      b = p;

      high = mid;

    }

  }

  return (a.second * (b.first - X) + b.second * (X - a.first) <= Y * (b.first - a.first));

}



int main() {

  int X, Y;

  cin >> X >> Y;

  if (X > Y) {

    swap(X, Y);

  }

  int low = 3, high = (int) 2e6;

  while (low < high) {

    int mid = (low + high + 1) >> 1;

    if (Solvable(mid, X, Y)) {

      low = mid;

    } else {

      high = mid - 1;

    }

  }

  cout << low - 1 << '\n';

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2384419366581725x):
/**

 *    author:  tourist

 *    created: 27.01.2020 01:09:52       

**/

#include <bits/stdc++.h>



using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  long long r, b;

  cin >> r >> b;

  auto Count = [&](long long p, long long q, long long bound) {

    long long sx = 0;

    long long sy = 0;

    long long cnt = 0;

    for (long long x = 0; x * p <= bound; x++) {

      long long y = (bound - x * p) / q;

      sx += x * (y + 1);

      sy += y * (y + 1) / 2;

      cnt += y + 1;

    }

    return make_tuple(sx, sy, cnt);

  };

  auto Test = [&](long long p, long long q) {

    bool inv = false;

    if (p < q) {

      swap(p, q);

      swap(r, b);

      inv = true;

    }

    long long low = 0, high = 1;

    while (true) {

      auto got = Count(p, q, high);

      if (get<0>(got) * p + get<1>(got) * q > r * p + b * q) {

        break;

      }

      low = high;

      high <<= 1;

    }

    while (low + 1 < high) {

      long long mid = (low + high) >> 1;

      auto got = Count(p, q, mid);

      if (get<0>(got) * p + get<1>(got) * q > r * p + b * q) {

        high = mid;

      } else { 

        low = mid;

      }

    }

    auto got = Count(p, q, low);

    long long sx = get<0>(got);

    long long sy = get<1>(got);

    long long cnt = get<2>(got);

    long long s = sx * p + sy * q;

    long long add = (r * p + b * q - s) / high;

    long long x = 0;

    while ((high - x * p) % q != 0) {

      ++x;

    }

    sx += x * add + q * (add * (add - 1) / 2);

    long long y = (high - x * p) / q;

    while (y >= p) {

      x += q;

      y -= p;

    }

    sy += y * add + p * (add * (add - 1) / 2);

    cnt += add;

    if (sx <= r && sy <= b) {

      cout << cnt - 1 << '\n';

      exit(0);

    }

    bool ret = (sx > r) ^ inv;

    if (inv) {

      swap(r, b);

    }

    return ret;

  };

  long long p0 = 0, q0 = 1;

  long long p1 = 1, q1 = 0;

  while (true) {

    if (Test(p0 + p1, q0 + q1)) {

      p0 = p0 + p1;

      q0 = q0 + q1;

    } else {

      p1 = p0 + p1;

      q1 = q0 + q1;

    }

  }

  return 0;

}