#include <bits/stdc++.h>
using namespace std;
int readSeconds()
{
int h, m, s;
cin >> h >> m >> s;
return h * 60 * 60 + m * 60 + s;
}
int main()
{
vector<int> cnt(24 * 60 * 60);
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int from = readSeconds();
int to = readSeconds();
cnt[from]++;
cnt[to]--;
}
for (int i = 1; i < cnt.size(); i++)
{
cnt[i] += cnt[i - 1];
}
int ans = 0;
for (int i = 8 * 60 * 60; i < 20 * 60 * 60; i++)
{
if (cnt[i] == 0)
{
ans++;
}
}
cout << ans << "\n";
return 0;
}