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
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define BOOST ios_base::sync_with_stdio(0), cin.tie(0)
template<typename T>
using vc = vector<T>;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;

int main(){
	BOOST;
	int x, d, h, m;
	cin >> x >> d >> h >> m;
	int left;
	if(x < 5){
		left = (23-(d-x))*1440 + (24-h-1)*60 + 60-m;
	}
	else if(x == 5){
		left = (24-(d-x))*1440 + (24-h-1)*60 + 60-m;
		if(d < 29 || h < 3) left -= 60;
	}
	cout << left << "\n";
}