import sys
input = sys.stdin.readline
N = int(input())
flower = []
last_start = 101
last_end = 301
temp_start = temp_end = count = 0
for i in range(N):
a, b, c, d = map(int, input().split())
start = a * 100 + b
end = c * 100 + d
if start != end:
flower.append((start, end))
flower.sort()
while last_end <= 1130 and count < 10000:
for i in range(N):
if flower[i][0] <= last_end and \
flower[i][1] > last_end and \
flower[i][0] >= temp_start and \
flower[i][1] >= temp_end:
temp_start = flower[i][0]
temp_end = flower[i][1]
last_start = temp_start
last_end = temp_end
count += 1
if count == 10000:
print(0)
else:
print(count)