package yukicoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { int count = Integer.parseInt(buff.readLine()); int ans = 0; while (count-- > 0) { String[] box = buff.readLine().split(" "); String[] goBox = box[0].split(":"); String[] getBox = box[1].split(":"); int go = 0; int get = 0; for (int i = 0; i < 2; ++i) { int mul = 1; if (i == 0) { mul = 60; } get += Integer.parseInt(getBox[i]) * mul; go += Integer.parseInt(goBox[i]) * mul; } if (get - go > 0) { ans += get - go; } else { ans += 24 * 60 - Math.abs(get - go); } } System.out.println(ans); } catch (NumberFormatException e) { e.getStackTrace(); } catch (IOException e) { e.getStackTrace(); } catch (Exception e) { e.getStackTrace(); } } }