h,m=map(int,input().split()) t=h*3600/11-m*60 if t>3927: t-=3927.272727 print(int(t))