1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
using ind = long long;
using cind = const ind;
#define FOR(i,l,r) for(ind i = (l); i <= (r); i++)
#define FORD(i,l,r) for(ind i = (l); i >= (r); i--)
#define DEBUG_ON false
#define debug if constexpr(DEBUG_ON)
#define err debug cerr

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ind x,d,h,m;
    cin >> x >> d >> h >> m;
    if(x == 5 and (h <= 2 or d <= 28)) h++;
    d-=23;
    if(x==5) x++;
    cout << (x-d)*24*60 + 24*60 - h*60 - m << '\n';
}