#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	int N;
	cin >> N;

	string S;
	vector<int> str;
	while( getline( cin, S, ':' ) )
	{
		istringstream ss( S );
		int a;
		while ( ss >> a )
		{
			str.push_back( a );
		}
	}
	int res{};
	REP( i, N*4 )
	{
		if( str[i] > str[i+2] )
		{
			str[i+2] = str[i+2] + 24;
		}
		if( str[i+2] == 0 )
		{
			str[i+2] = 12;
		}
		int M = str[i] * 60 + str[i+1];
		int N = str[i+2] * 60 + str[i+3];
		res += N - M;
		i += 3;
	}
	cout << res << endl;
	return 0;
}