1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <bits/stdc++.h>

using namespace std;
int f[] = {0, 2160, 3600, 5040, 6480, 9300};
int main(){
	int x, d, h, m; cin >> x >> d >> h >> m;
	if(d == 29 && h > 2) m -= 60;
	d -= 23, h -= 12;
	int t = d*1440+h*60+m;
	cout << f[x]-t;
	
}