#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int **F = new int*[n];
int curr[4]; // start_month, day / end_month, day
curr[0] = 3;
curr[1] = 1;
curr[2] = 11;
curr[3] = 30;
int tmp[2];
tmp[0] = 0;
tmp[1] = 0;
for (int i = 0; i < n; i++)
{
F[i] = new int[4];
cin >> F[i][0] >> F[i][1] >> F[i][2] >> F[i][3];
}
int cnt = 0;
int flag = 0;
while (1) {
flag = 0;
for (int i = 0; i < n; i++)
{
if ((curr[0] > F[i][0]) || ((curr[0] == F[i][0]) && (curr[1] >= F[i][1])))
{
if ((tmp[0] < F[i][2]) || ((tmp[0] == F[i][2]) && (tmp[1] < F[i][3]))) // 가장 높은 end value 탐색
{
tmp[0] = F[i][2];
tmp[1] = F[i][3];
flag = 1;
}
}
}
curr[0] = tmp[0];
curr[1] = tmp[1];
cnt++;
if (flag == 0)
{
cnt = 0;
break;
}
if ((curr[0] > curr[2]) || ((curr[0] == curr[2]) && (curr[1] > curr[3])))
break;
}
cout << cnt;
}