#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int M, N;
int step;
while (cin >> M >> N)
{
if (M > N)
{
int temp = M;
M = N;
N = temp;
}
int mx, my, mz;
int nx, ny, nz;
mx = (int)sqrt(M - 1) + 1;
my = (M - (mx - 1)*(mx - 1) + 1) / 2;
mz = (mx*mx - M) / 2 + 1;
nx = (int)sqrt(N - 1) + 1;
ny = (N - (nx - 1)*(nx - 1) + 1) / 2;
nz = (nx*nx - N) / 2 + 1;
step = abs(mx - nx) + abs(my - ny) + abs(mz - nz);
cout << step << endl;
}
return 0;
}