from bisect import bisect_left A, B = map(int, input().split()) x = [0, 3927, 7854, 11781, 15709, 19636, 23563, 27490, 31418, 35345, 39272, 43200] t = (A * 60 + B) * 60 % (12 * 60 * 60) print(x[bisect_left(x, t)] - t)