1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;



int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    cout << (23+x+(x==5)-d)*24*60 + (23-h)*60 + (60-m) - (x == 5 && (d < 29 || h < 2) ? 60 : 0) << "\n";

    return 0;
}