#include using namespace std; typedef long long ll; int main() { int A, B; cin >> A >> B; double t = 60 * 60 * A + B * 60; double t1 = 6 * B; double t2 = (30 * A) % 360 + (double)B / 2; while (abs(t1 - t2) > 0.1) { t += 0.01; double s = ((int)t) % 60; double m = ((int)t / 60) % 60; int h = ((int)t / 3600) % 12; t1 = 6 * m + s / 10.0; t2 = (30 * h) % 360 + m / 2.0 + s / 120.0; } cout << (int)(t - (3600 * A + 60 * B)) << "\n"; return 0; }