A rectangle in the Cartesian plane is given by two corner points (x1,y1) and (x2,y2), its lower-left and upper-right corners, with x1≤x2 and y1≤y2.
For two rectangles A=((x1A,y1A),(x2A,y2A)) and B=((x1B,y1B),(x2B,y2B)), we say that A precedes B, written A⪯B, when
x2A<x1Bandy2A<y1B.
You are given a collection of rectangles in the plane. Find the length L of the longest sequence of rectangles (A1,A2,…,AL) from the collection such that
A1⪯A2⪯⋯⪯AL.
The input contains several test cases. Each test case starts with a line containing one integer n (1≤n≤100000), the number of rectangles. Each of the next n lines contains four integers x1 y1 x2 y2 (−1000000≤x1≤x2≤1000000 and −1000000≤y1≤y2≤1000000), the lower-left and upper-right corners of one rectangle. The input ends with a line containing a single 0.
For each test case, print one line with a single integer: the length of the longest chain of rectangles.