a, b = map(int, input().split()) ans = 2023 for x in range(a + 1): if b - a + x < 0: continue ans = min(ans, abs(b - 3 * a + 4 * x)) print(ans)