program internetas;
  const
    fin = 'internetas.in';
    fout = 'internetas.out';
  var
    f1, f2: text;
    ah, amin, bh, bmin, i, j, k: integer;
    t1, t2, l1, l2, sum: integer;


function toAbs (h, m: integer): integer;
begin { toAbs }
  toAbs := (h - 1) * 60 + m;
end; { toAbs }


function min (a, b: integer): integer;
begin
  if a < b then min := a else min := b;
end;

function max (a, b: integer): integer;
begin
  if a > b then max := a else max := b;
end;

function intersection (a1, a2, b1, b2: integer): integer;
  var
    l1, l2, diff: integer;
begin
  l1 := max (a1, b1);
  l2 := min (a2, b2);
  diff := l2 - l1;
  if diff > 0
    then intersection := diff
    else intersection := 0;
end;

begin
  assign (f1, fin);
  assign (f2, fout);
  reset (f1);
  rewrite (f2);
  readln (f1, ah, amin, bh, bmin);
  readln (f1, k);

  l1 := toAbs (ah, amin);
  l2 := toAbs (bh, bmin);
  sum := l2 - l1;

  for i := 1 to k do begin
    readln (f1, ah, amin, bh, bmin);
    t1 := toAbs (ah, amin);
    t2 := toAbs (bh, bmin);
    sum := sum - intersection (l1, l2, t1, t2);
  end;
  writeln (f2, sum);

  close (f1);
  close (f2);
end.
