#include <bits/stdc++.h>
using namespace std;
const long long M = 1e3 + 7, mod = 1e9 + 7;
long long n, d, S[M];
vector<long long> g1[M], g[M];
void dfs(long long node) {
  S[node] = -1;
  long long c = 0;
  for (auto u : g[node]) {
    if (S[u] == 0) dfs(u);
    c = max(c, S[u]);
  }
  S[node] = c + 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    cin >> n >> d;
    for (long long i = 1; i <= d; i++) {
      for (long long j = 1; j <= n; j++) {
        long long x;
        cin >> x;
        g1[x].push_back(j);
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        if (i == j) continue;
        bool ok = 1;
        for (long long k = 0; k < d; k++) {
          if (g1[i][k] > g1[j][k]) ok = 0;
        }
        if (ok) g[i].push_back(j);
      }
    }
    long long ans = 1;
    for (long long i = 1; i <= n; i++) {
      if (S[i] == 0) dfs(i);
    }
    for (long long i = 1; i <= n; i++) ans = max(ans, S[i]);
    cout << ans << "\n";
  }
  return 0;
}
