a, b = map(int, input().split()) a = a if a < 12 else a - 12 x, ans = 30000, 0 for t in range(0, 7200): at = ((a * 5) + ((b * 60 + t) * 5 / 3600)) % 60 bt = (b * 60 + t) * (1 / 60) % 60 m = abs(at - bt) if x > m: x, ans = m, t else: if x == 0: print(t - 1) else: print(t - 2) break