import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class clock_sm {
	final int MOD = 24 * 60 * 60;

	int toTime(String str) {
		assert str.charAt(2) == ':' && str.charAt(5) == ':';
		int h = Integer.parseInt(str.substring(0, 2));
		assert 0 <= h && h <= 23;
		int m = Integer.parseInt(str.substring(3, 5));
		assert 0 <= m && m <= 59;
		int s = Integer.parseInt(str.substring(6, 8));
		assert 0 <= s && s <= 59;
		return (h * 60 + m) * 60 + s;
	}

	class State implements Comparable<State> {
		int time, dist;

		public State(int time, int dist) {
			super();
			this.time = time;
			this.dist = dist;
		}

		@Override
		public int compareTo(State o) {
			if (dist != o.dist)
				return dist - o.dist;
			return time - o.time;
		}
	}

	void solve() throws IOException {
		int from = toTime(br.readLine());
		int to = toTime(br.readLine());
		int l = Integer.parseInt(br.readLine());
		PriorityQueue<State> pq = new PriorityQueue<State>();
		pq.add(new State(from, 0));
		boolean[] used = new boolean[MOD];
		int[] best = new int[MOD];
		Arrays.fill(best, Integer.MAX_VALUE);
		while (!pq.isEmpty()) {
			State st = pq.poll();
			// System.err.println(st.time + " " + pq.size());
			if (st.time == to) {
				out.println(st.dist);
				return;
			}
			if (used[st.time])
				continue;
			{
				int nt = (st.time + 1) % MOD;
				int nd = st.dist + 1;
				if (!used[nt] && nd < best[nt]) {
					pq.add(new State(nt, nd));
					best[nt] = nd;
				}
			}
			{
				int nt = (st.time + l) % MOD;
				int om = (nt / 60) % 60;
				int nm = (om + 1) % 60;
				nt -= om * 60;
				nt += nm * 60;
				int nd = st.dist + l;
				if (!used[nt] && nd < best[nt]) {
					pq.add(new State(nt, nd));
					best[nt] = nd;
				}
			}

		}
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	public void run() {
		try {
			String filename = "clock";
			br = new BufferedReader(new FileReader(filename + ".in"));
			out = new PrintWriter(filename + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	String nextToken() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				String s = br.readLine();
				if (s == null) {
					return null;
				}
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Integer.parseInt(nextToken());
	}

	public static void main(String[] args) {
		new clock_sm().run();
	}
}
