#include <bits/stdc++.h> using namespace std; int main() { int d, h, m; cin >> d >> h >> m; int res = (d - 11) * 24 * 60 + (h - 11) * 60 + m - 11; if (res < 0) puts("-1"); else cout << res << endl; return 0; }