a,b = map(int,input().split()) if a>b:a,b=b,a f=lambda x:abs(a+b-4*x) print(min(f(min(a,(a+b)//4)),f(min(a,(a+b+3)//4))))