A,B=map(int,input().split()) A%=12 L=B*6 S=A*30+B/2 if S>=L: ans=int((S-L)*120/11) else: ans=int((S+360-L)*120/11) print(ans)