A, B = map(int, input().split()) sec = A * 3600 + B * 60 for i in range(22): if 86400 * i // 22 >= sec: print(86400 * i // 22 - sec) break