#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const long long N = 1e5 + 10;
const long long IM = 1e15 + 37;
const long long PI = 3.14159265;
void PV(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << " ";
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void PP(long long n) { cout << n; }
inline void PP(long long n, long long m) { cout << n << " " << m << "\n"; }
inline void PP(long long n, long long m, long long q) {
  cout << n << " " << m << " " << q << "\n";
}
inline void PP(long long n, long long m, long long q, long long u) {
  cout << n << " " << m << " " << q << " " << u << "\n";
}
inline void op() {}
long long n, k, kk;
vector<long long> v[N];
long long vis[N];
long long dp[N];
void dfs(long long x) {
  vis[x] = 1;
  if (!dp[x]) dp[x]++;
  for (auto i : v[x]) {
    if (vis[i] == 0) {
      dfs(i);
    }
    dp[x] = max(dp[i] + 1, dp[x]);
  }
  kk = max(kk, dp[x]);
}
long long a[5][1005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  op();
  long long i, j, x, y, u, l;
  {
    i = j = x = y = u = l = 0;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
      for (j = 0; j < n; j++) {
        cin >> x;
        a[i][x] = j + 1;
      }
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        l = 1;
        for (x = 0; x < k; x++) {
          if (a[x][i] >= a[x][j]) l = 0;
        }
        if (l) v[i].push_back(j);
      }
    }
    for (i = 1; i <= n; i++) {
      if (!vis[i]) dfs(i);
    }
    cout << (kk) << "\n";
  }
  return 0;
}
