a,b=map(int,input().split()) ans=a+b for i in range(min(a,b)+1): res=abs(a+b-4*i) ans=min(res,ans) print(ans)