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[] getBox = box[0].split(":"); String[] goBox = box[1].split(":"); int[] get = new int[2]; int[] go = new int[2]; for(int i = 0; i < 2; ++i){ get[i] = Integer.parseInt(getBox[i]); go[i] = Integer.parseInt(goBox[i]); } int first = 0; int second = 0; if(get[1] > go[1]){ first--; go[1] += 60; } second = go[1] - get[1]; if(get[0] > go[0]){ first += 24 - (get[0] - go[0]); }else{ first += go[0] - get[0]; } ans += first * 60 + second; } System.out.println(ans); } catch (NumberFormatException e) { e.getStackTrace(); } catch (IOException e) { e.getStackTrace(); } catch (Exception e) { e.getStackTrace(); } } }