Genomes

No attempts yetTime limit1sMemory limit128 MB

Problem

Biologists working in comparative genetics are looking for gene sequences that are conserved across a set of species.

Let the set {1,2,,n}\{1, 2, \dots, n\} denote the genes, so that each number corresponds to one gene. Every species is described by a permutation of 1,2,,n1, 2, \dots, n that gives the ordering of its genes. A gene sequence x1,x2,,xkx_1, x_2, \dots, x_k is a conserved gene sequence for a set of species if it is a subsequence (not necessarily contiguous) of the gene ordering of every one of those species.

Write a program that reads the gene orderings from standard input, determines the length of the longest conserved sequence, and writes that length to standard output.

Input

The first line contains two integers nn and mm separated by a single space, with 1n5001 \le n \le 500 and 1m201 \le m \le 20. Here nn is the number of genes and mm is the number of species. Each of the next mm lines contains the genome of one species, written as a permutation of 1,2,,n1, 2, \dots, n with the numbers separated by single spaces.

Output

Print a single integer equal to the length of the longest conserved gene sequence.