
#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s, t;
ll prime[2000000];

// < ----------- func eh ---------------- ? //



// <------------- Start of main() -------------------> //

void MAIN() {
	ll h, m1, m2;
	cin >> h >> m1; m1 += 60 * h;
	cin >> h >> m2; m2 += 60 * h;

	cin>>k;
	m2-=k;

	cout<<max(0ll,m2-m1);newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int par[10010];

void init(int n){
	REP(i,n){
		par[i]=i;
	}
}

int find(int x){
	if(par[x]==x){
	   return x;
	}else{
	  return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return;

	par[x]=y;
}

bool same(int x,int y){
	return find(x)==find(y);
}

struct edge { int from,to,cost; };

bool comp(const edge& e1,const edge& e2){
	return e1.cost<e2.cost;
}

edge es[100010];

int V,E;

int kruskal(){
	sort(es,es+E,comp);
	init(V);
	int res=0;
	REP(i,E){
		edge e=es[i];
		if(!same(e.from,e.to)){
			unite(e.from,e.to);
			res+=e.cost;
		}
	}
	return res;
}

int main(void){

	          cin >> V >> E;
	          REP(i,E){
	        	  cin >> es[i].from >> es[i].to >> es[i].cost;
	          }

	          cout << kruskal() << endl;

	          return 0;
}