#include <bits/stdc++.h>
using namespace std;
int64_t ar[1001][1001];
int64_t temp[1001];
int64_t graph[1001][1002];
int64_t dep[1001];
int64_t n, k;
int64_t ans = 1;
set<int64_t> toko;
void dfs(int64_t i) {
  dep[i] = 1;
  toko.insert(i);
  queue<int64_t> q;
  q.push(i);
  while (!q.empty()) {
    int64_t kk = q.front();
    q.pop();
    for (int64_t j = 1; j <= graph[kk][0]; j++) {
      if (dep[graph[kk][j]] <= dep[kk]) {
        q.push(graph[kk][j]);
        dep[graph[kk][j]] = dep[kk] + 1;
      }
    }
    ans = max(ans, dep[kk]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int64_t i = 0; i < k; i++) {
    for (int64_t j = 0; j < n; j++) {
      cin >> temp[j];
    }
    for (int64_t j = 0; j < n; j++) {
      for (int64_t l = j + 1; l < n; l++) {
        ar[temp[j]][temp[l]]++;
      }
    }
  }
  for (int64_t i = 1; i <= n; i++) {
    for (int64_t j = 1; j <= n; j++)
      if (ar[i][j] == k) {
        toko.insert(j);
        ++graph[i][0];
        graph[i][graph[i][0]] = j;
      }
  }
  for (int64_t i = 1; i <= n; i++) {
    if (toko.find(i) == toko.end()) dfs(i);
  }
  cout << ans << "\n";
}
