#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)

int main(){
    int n; cin >> n;
    int sh, sm, wh, wm;
    int s,w;
    int res = 0;
    rep(i,n){
        scanf("%d:%d",&sh,&sm);
        scanf("%d:%d",&wh,&wm);
        s = sh*60 + sm;
        w = wh*60 + wm;
        if(s>w){ w+=60*24; }
        res += (w - s);
    }
    cout << res << endl;
    return 0;
}