public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		while (in.hasNext()) {
			int size = in.nextInt();
			if (size == 0)
				break;
			blocks = new Point[size];
			for (int i = 0; i < size; i++)
				blocks[i] = new Point(in.nextInt(), in.nextInt());
			Arrays.sort(blocks, new OrderBlocks());
			out.append(findLIS(size) + "\n");
		}
		System.out.print(out + "*\n");
	}