#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
const int NMAX = 1010;
int N, K, V[10][NMAX], Pos[10][NMAX], Best[NMAX], Ans;
vector<int> G[NMAX];
bool Used[NMAX];
void DFS(int Node) {
  Used[Node] = 1;
  for (int i = 0; i < G[Node].size(); ++i) {
    if (!Used[G[Node][i]]) DFS(G[Node][i]);
    Best[Node] = max(Best[Node], Best[G[Node][i]] + 1);
  }
  Best[Node] = max(Best[Node], 1);
  Ans = max(Ans, Best[Node]);
}
int main() {
  scanf("%i %i", &N, &K);
  for (int i = 1; i <= K; ++i)
    for (int j = 1; j <= N; ++j) {
      scanf("%i", &V[i][j]);
      Pos[i][V[i][j]] = j;
    }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) {
      if (i == j) continue;
      bool OK = 1;
      for (int k = 1; k <= K; ++k)
        if (Pos[k][i] >= Pos[k][j]) OK = 0;
      if (OK) G[i].push_back(j);
    }
  for (int i = 1; i <= N; ++i)
    if (!Used[i]) DFS(i);
  printf("%i\n", Ans);
}
