{$r+}
uses
    sysutils;
const
    MAXL = 10;
    MAXV = 60 * 60 * 24;
type
    int = longint;
    
    time = record
        h, m, s : int;
    end;

    queue = record
        data : array [1..MAXV + 1] of time;
        l, r : int;
    end;

var
    s : string;
    start, finish : time;
    l : int;

procedure init(var q : queue);
begin
    q.l := 1;
    q.r := 0;
end;

function is_empty(const q : queue) : boolean;
begin
    result := q.l > q.r;
end;

procedure push(var q : queue; x : time);
begin
    inc(q.r);
    q.data[q.r] := x;
end;

function pop(var q : queue) : time;
begin                   
    result := q.data[q.l];
    inc(q.l);
end;



function str_to_time(const s : string) : time;
var
    ans : time;
begin
    ans.h := strtoint(copy(s, 1, 2));
    assert((0 <= ans.h) and (ans.h <= 23));
    ans.m := strtoint(copy(s, 4, 2));
    assert((0 <= ans.m) and (ans.m <= 59));
    ans.s := strtoint(copy(s, 7, 2));
    assert((0 <= ans.s) and (ans.s <= 59));

    result := ans;
end;

function time_to_str(const t : time) : string;
// DEBUG function
begin
    result := inttostr(t.h) + ':' + inttostr(t.m) + ':' + inttostr(t.s);
end;

function time_to_int(const t : time) : int;
begin
    result := t.s + t.m * 60 + t.h * 3600;
end;

function time_plus_second(const t : time) : time;
begin
    result.s := (t.s + 1) mod 60;
    result.m := ((t.s + 1) div 60 + t.m) mod 60;
    result.h := (((t.s + 1) div 60 + t.m) div 60 + t.h) mod 24;
end;

function time_plus_button(const t : time; l : int) : time;
var
    i : int;
begin   
    result := t;
    for i := 1 to l do begin
        result := time_plus_second(result);
    end;
    result.m := (result.m + 1) mod 60;
end;



var
    q : array [0..MAXL] of queue;
        
function BFS(start, finish : time; l : int) : int;
// реализация 1-l BFS на (l + 1) очереди
var
    current_dist, current_queue, i, dv : int;
    v, u : time;
    dist : array [0..MAXV] of int;
    
begin
    for i := 0 to l do begin
        init(q[i]);
    end;
    for i := 0 to MAXV do begin
        dist[i] := MAXV;
    end;
    dist[time_to_int(start)] := 0;
    current_dist := 0;
    push(q[0], start);
                      
    while (true) do begin
        current_queue := current_dist mod (l + 1);
        
        while (not is_empty(q[current_queue])) do begin
            v := pop(q[current_queue]);
            if (time_to_int(v) = time_to_int(finish)) then begin
                result := dist[time_to_int(finish)];
                exit;
            end;


            dv := dist[time_to_int(v)];
            if (dv < current_dist) then begin
                // данная вершина была обработана раньше
                continue;
            end;

            u := time_plus_second(v);
            if (dist[time_to_int(u)] > dv + 1) then begin
                dist[time_to_int(u)] := dv + 1;
                push(q[(dv + 1) mod (l + 1)], u);
            end;

            u := time_plus_button(v, l);
            if (dist[time_to_int(u)] > dv + l) then begin
                dist[time_to_int(u)] := dv + l;
                push(q[(dv + l) mod (l + 1)], u);
            end;
        end;

        inc(current_dist);
        init(q[current_queue]);
    end;
    
end;

begin
    reset(input, 'clock.in');
    rewrite(output, 'clock.out');

    readln(s);
    start := str_to_time(s);
    readln(s);
    finish := str_to_time(s);

    read(l);
    assert((1 <= l) and (l <= MAXL));

    writeln(BFS(start, finish, l));
end.
