a, b = map(int,input().split()) sec = (a * 60 + b) * 60 positionA = (sec % (3600*12)) / (3600 * 12) * 100 positionB = (sec % 3600) / 3600 * 100 minimum = 9999 minimumS = -1 addSec = 0 while True: addSec += 1 positionA_next = ((sec + addSec) % (3600 * 12)) / (3600 * 12) * 100 positionB_next = ((sec + addSec) % 3600) / 3600 * 100 if (positionB <= positionA) and (positionB_next >= positionA_next): break positionA ,positionB = positionA_next, positionB_next print(addSec-1)