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