from bisect import bisect_left a,b=map(int,input().split()) x=[i * 12 * 60 * 60 / 11 for i in range(12)] t=(a * 60 + b)%(12*60)*60 print(int(x[bisect_left(x,t)]-t))