#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int K = 8;
int n, k;
int A[K][N];
int pos[N][N];
vector<int> G[N];
int DP[N];
int vis[N];
int ans = 0;
void dfs(int x, int val) {
  for (auto xx : G[x]) {
    if (DP[xx] < val + 1) {
      DP[xx] = val + 1;
      vis[xx] = 1;
      dfs(xx, val + 1);
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) DP[i] = 1;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> A[i][j];
      pos[i][A[i][j]] = j;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int flag = 0;
      for (int x = 1; x <= k; x++) {
        if (pos[x][i] >= pos[x][j]) flag = 1;
      }
      if (!flag) G[i].push_back(j);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, 1);
  }
  for (int i = 1; i <= n; i++) ans = max(ans, DP[i]);
  cout << ans << endl;
}
