a,b=map(int,input().split())
if a<b:
    a,b=b,a
v=(a+b)%4
print(max(a-3*b,min(v,4-v)))