from bisect import bisect_left lst = [0] for i in range(1, 11): lst.append(12 * 60 * 60 * i / 11) lst.append(12 * 60 * 60) a, b = map(int, input().split()) a %= 12 sec = a * 60 * 60 + b * 60 print(int(lst[bisect_left(lst, sec)] - sec))