//No.70 睡眠の重要性! import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class No70 { static final InputStream in = System.in; static final PrintWriter out = new PrintWriter(System.out,false); static void solve() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int ans = 0; while (n-- > 0) { String[] input = br.readLine().split(" "); int h1 = Integer.parseInt(input[0].split(":")[0]); int m1 = Integer.parseInt(input[0].split(":")[1]); int h2 = Integer.parseInt(input[1].split(":")[0]); int m2 = Integer.parseInt(input[1].split(":")[1]); if (h1 >= h2) { if (m1 >= m2) { ans += (24-h1+h2-1)*60 + 60-(m1-m2); }else { ans += (24-h1+h2)*60 + (m2-m1); } }else { if (m1 >= m2) { ans += (h2-h1-1)*60 + 60-(m1-m2); }else { ans += (h2-h1)*60 + (m2-m1); } } } out.println(ans); } public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); } static void trace(Object... o) { System.out.println(deepToString(o));} }