1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <bits/stdc++.h>
using namespace std;
int x,d,h,m;
int main() {
  scanf("%d%d%d%d",&x,&d,&h,&m);
  if (d==29 && h>=3) --h;
  d=d-(22+x);
  int tot=48*60-(d*24+h)*60-m;
  if (x==5) tot+=23*60;
  printf("%d\n",tot);
  return 0;
}