A,B = map(int, input().split()) A=A%12 s=0 while (A*3600+B*60+s)%43200!=(B*720+s*12)%43200: if ((A*3600+B*60+s)%43200-(B*720+s*12)%43200)*((A*3600+B*60+(s+1))%43200-(B*720+(s+1)*12)%43200)<0 and (B*720+(s+1)*12)%43200!=0: break s+=1 print(s)