const maxn = 1000;
maxm = 10;
var n: word;
m: byte;
d,a: array[1..maxm,1..maxn] of word;
f: array[0..maxn] of word;
function check(a,b:word):boolean;
var i:word;
begin
check:=true;
for i:=2 to m do
if (d[i,a]>d[i,b]) then
begin
check:=false;
break;
end;
end;
procedure enter;
var i,j,res:word;
b:boolean;
begin
readln(n,m);
res:=0;
for i:=1 to m do
begin
for j:=1 to n do
begin
read(a[i,j]);
d[i,a[i,j]]:=j;
end;
readln;
end;
f[0]:=0;
for i:=1 to n do
begin
f[a[1,i]]:=1;
for j:=1 to i-1 do
if check(a[1,j],a[1,i]) then
if f[a[1,j]]+1>f[a[1,i]] then
f[a[1,i]]:=f[a[1,j]]+1;
if f[a[1,i]]>res then res:=f[a[1,i]]
end;
writeln(res);
end;
begin
enter;
end.
Y29uc3QgbWF4biA9IDEwMDA7IAogICAgICBtYXhtID0gMTA7CnZhciBuOiB3b3JkOwogICAgbTogYnl0ZTsKICAgIGQsYTogYXJyYXlbMS4ubWF4bSwxLi5tYXhuXSBvZiB3b3JkOwogICAgZjogYXJyYXlbMC4ubWF4bl0gb2Ygd29yZDsKZnVuY3Rpb24gY2hlY2soYSxiOndvcmQpOmJvb2xlYW47CnZhciBpOndvcmQ7CmJlZ2luCiAgY2hlY2s6PXRydWU7CiAgZm9yIGk6PTIgdG8gbSBkbwogIGlmIChkW2ksYV0+ZFtpLGJdKSB0aGVuIAogIGJlZ2luCiAgICBjaGVjazo9ZmFsc2U7CiAgICBicmVhazsKICBlbmQ7CmVuZDsKcHJvY2VkdXJlIGVudGVyOwp2YXIgaSxqLHJlczp3b3JkOwogICAgYjpib29sZWFuOwpiZWdpbgogIHJlYWRsbihuLG0pOwogIHJlczo9MDsKICBmb3IgaTo9MSB0byBtIGRvCiAgYmVnaW4KICAgIGZvciBqOj0xIHRvIG4gZG8KICAgIGJlZ2luCiAgICAgIHJlYWQoYVtpLGpdKTsKICAgICAgZFtpLGFbaSxqXV06PWo7CiAgICBlbmQ7CiAgICByZWFkb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