1
2
3
4
5
6
k = (0,25,26,27,28,30)
x,d,h,m = map(int,input().split())
a = k[x]*24*60-((d*24+h)*60+m)
if x==5 and (d<29 or h<2):
	a -= 60
print(a)