#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
using namespace std;
long long n, m, a, i, j, ol, res, f[1011][1011], k, ff[1011], s, maxres;
vector<long long> vc[1111];
void go(long long v, long long x) {
  if (ff[v] >= x) return;
  ff[v] = x;
  maxres = max(maxres, x);
  for (long long i = 0; i < vc[v].size(); ++i) go(vc[v][i], x + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (i = 1; i <= k; ++i)
    for (j = 1; j <= n; ++j) {
      cin >> a;
      f[i][a] = j;
    }
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j) {
      long long ol = 0;
      for (long long ij = 1; ij <= k; ++ij)
        if (f[ij][i] >= f[ij][j]) ol = 1;
      if (i != j && ol == 0) vc[i].push_back(j);
    }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) ff[j] = 0;
    go(i, 1LL);
  }
  cout << maxres << "\n";
  return 0;
}
