#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; int main() { int a, b; cin >> a >> b; a %= 12; int t = a * 60 * 60 + b * 60; if (t == 0) { cout << 0 << '\n'; } else if (t <= 1 * 60 * 60 + 5 * 60 + 27) { cout << 1 * 60 * 60 + 5 * 60 + 27 - t << '\n'; } else if (t <= 3 * 60 * 60 + 16 * 60 + 21) { cout << 3 * 60 * 60 + 16 * 60 + 21 - t << '\n'; } else if (t <= 4 * 60 * 60 + 21 * 60 + 49) { cout << 4 * 60 * 60 + 21 * 60 + 49 - t << '\n'; } else if (t <= 5 * 60 * 60 + 27 * 60 + 16) { cout << 5 * 60 * 60 + 27 * 60 + 16 - t << '\n'; } else if (t <= 6 * 60 * 60 + 32 * 60 + 43) { cout << 6 * 60 * 60 + 32 * 60 + 43 - t << '\n'; } else if (t <= 7 * 60 * 60 + 38 * 60 + 10) { cout << 7 * 60 * 60 + 38 * 60 + 10 - t << '\n'; } else if (t <= 8 * 60 * 60 + 43 * 60 + 38) { cout << 8 * 60 * 60 + 43 * 60 + 38 - t << '\n'; } else if (t <= 9 * 60 * 60 + 49 * 60 + 5) { cout << 9 * 60 * 60 + 49 * 60 + 5 - t << '\n'; } else if (t <= 10 * 60 * 60 + 54 * 60 + 32) { cout << 10 * 60 * 60 + 54 * 60 + 32 - t << '\n'; } else { cout << 12 * 60 * 60 - t << '\n'; } return 0; }