import sys input = sys.stdin.readline def MI(): return map(int, input().split()) import math a,b=MI() a%=12 for sec in range(3600*2): newb=b+sec//60 newa=a+0 if 60<=newb<120: newa+=1 elif newb>=120: newa+=2 newa%=12 newb%=60 nsec=sec%60 #print(newa,newb,sec) #print(11*sec+660*newb-3600*newa) if -11<11*nsec+660*newb-3600*newa<=0: print(sec) break