/*数学规律,第一种方法:找3种层数之差加起来 横向 左斜 右斜
第二种: 找出上面的点 的辐射范围
*/
#include<cstdio>
#include<cstring>#include<cmath>
#include<cstdlib>
int main()
{
int m,n;
while(scanf("%d%d",&m,&n)==2)
{
int temp;
if(m > n)
{
temp = m;
m = n;
n = temp;
}
int hm = ceil(sqrt(m));
int hn = ceil(sqrt(n));
int lm = (m-(hm-1)*(hm-1)-1)/2+1;
int ln = (n-(hn-1)*(hn-1)-1)/2+1;
int rm = (hm*hm-m)/2+1;
int rn = (hn*hn-n)/2+1;
printf("%d\n",abs(hm-hn)+abs(lm-ln)+abs(rm-rn));
}
return 0;
}