import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Test2{ public static void main(String[] args) { try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); System.out.println(CalcTime(br, N)); } catch(IOException e){ e.getStackTrace(); } catch(NumberFormatException e){ e.getStackTrace(); } } public static long CalcTime(BufferedReader br, int n) throws IOException{ int ans = 0; for(int i=0; i< n; i++){ String[] str = br.readLine().split(" "); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); Date timeTo =new Date(); Date timeFrom = new Date(); try{ timeFrom = sdf.parse(str[0]); timeTo = sdf.parse(str[1]); }catch(ParseException e){ e.getStackTrace(); } long timeFrom1 = timeFrom.getTime(); long timeTo1 = timeTo.getTime(); long timeDiff = (timeTo1 - timeFrom1) / (1000*60); if(timeDiff < 0 ) timeDiff += 1440; ans += timeDiff; } return ans; } }