A,B=map(int,input().split())
T=12*60*60/11
M=((12-A)*60-B)*60%T
print(int(M))