#include <bits/stdc++.h>
using namespace std;
int solve(vector<vector<int> >& perm, vector<vector<int> >& pos,
          vector<int>& LCS, int cur) {
  if (LCS[cur] == 0) {
    LCS[cur] = 1;
    int best = 0;
    int val = perm[0][cur];
    for (int i = cur + 1; i < (int)LCS.size(); ++i) {
      int nextval = perm[0][i];
      bool ok = true;
      for (int j = 1; j < (int)pos.size(); ++j)
        if (pos[j][val] > pos[j][nextval]) ok = false;
      if (ok) best = max(best, solve(perm, pos, LCS, i));
    }
    LCS[cur] += best;
  }
  return LCS[cur];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> LCS(n, 0);
  vector<vector<int> > perm(k, vector<int>(n));
  vector<vector<int> > pos(k, vector<int>(n));
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> perm[i][j];
      --perm[i][j];
      pos[i][perm[i][j]] = j;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(ans, solve(perm, pos, LCS, i));
  cout << ans << endl;
}
