Longest Increasing Subsequence in a matrix - Easy

时间限制: 3000 ms 内存限制: 65536 kb
总通过人数: 0 总提交人数: 0

Description

Given a non empty M x N matrix with numbers. Starting from row 0 to row M-1.

You can pick at most one number from each row.

Find the max length of longest increasing sequence. 

Input

First line contains a number M

Second lines contains a number N

The rest M lines would have N number each line separated by space

Output

Output a number indicates the answer

Sample Input 1

4
4
2 2 1 4
10 6 4 8
3 7 9 10
3 3 3 9

Sample Output 1

4

Hint 1

[2 , 6 , 7 , 9]

Sample Input 2

3
3
1 1 1
1 1 1
1 1 1

Sample Output 2

1

Sample Input 3

4
3
1 1 1
3 3 3
2 2 2
4 4 4

Sample Output 3

3

Hint 3

[1 , 3 , 4] would be the answer

Constraints

$ 1 \le M*N \le 4000 $

$ -10^{4} \le Matrix_{ij} \le 10^{4} $

相关推荐