#include <bits/stdc++.h>
using namespace std;
/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}
/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*ここから*/
int main() {
    int P,Q,R;
    cin >> P >> Q >> R;
    int max = 0;
    if(P>Q){
        max = P;
    }else{
        max = Q;
    }
    if(max<R){
        max = R;
    }
    cout << P+Q+R-max << endl;
}
#include <stdio.h>
int main()
{
    int hour_1;
    int hour_2;
    int min_1;
    int min_2;
    int k;
    scanf("%d %d %d %d %d", &hour_1, &min_1, &hour_2, &min_2, &k);
    int total_hour = hour_2 - hour_1;
    int total_minute = min_2 - min_1;
    int duration = (total_hour * 60) + total_minute - k;
    printf("%d\n", duration);
}