import sys input = sys.stdin.readline A, B = map(int, input().split()) x = A % 12 * 30 + B * 0.5 y = B * 6 print(int((x - y) % 360 / 5.5 * 60))