#include <bits/stdc++.h>
using namespace std;
int main() {
int h1,h2,m1,m2;
cin>>h1>>m1>>h2>>m2;
while((h1,h2,m1,m2)!=0){
if(h1==0)h1=24;
if(h2==0)h2=24;
if(h2>h1)
{
if(m2>m1)
cout<<(h2-h1)*60+(m2-m1);
else
cout<<((m2-m1)+60)+((h2-1)-h1)*60;
}
if(h2<=h1)
{
if(m2>m1)
cout<<((h2-h1)+24)*60+(m2-m1);
else
cout<<((m2-m1)+60)+(((h2-1)-h1)+24)*60;
}
}
return 0;
}