1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h> 

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pb push_back
#define F first 
#define S second
#define INF (ll)2e18
#define pii pair<int,int>
#define int ll

void solve() {

    int x,d,h,m; cin >> x >> d >> h >> m;
    if (x < 5){
        cout << (23+x - d) * 1440 + (23 - h) * 60 + (59 - m) + 1 << '\n';
    } else {
        int res = (29 - d) * 1440 + (23 - h) * 60 + (59 - m) + 1;
        if (d < 29 || (d == 29 && h < 2)){
            res -= 60;
        } 
        cout << res << '\n';
    }
    
}


int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}