#include <bits/stdc++.h>
using namespace std;
int a[1010][5];
vector<pair<int, int>> vt;
int dp[1010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    for (int y = 0; y < n; y++) {
      int q;
      scanf("%d", &q);
      a[q][i] = y;
    }
  }
  for (int i = 1; i <= n; i++) {
    vt.push_back({a[i][0], i});
  }
  sort(vt.begin(), vt.end());
  int dap = 0;
  for (int i = 0; i < vt.size(); i++) {
    int gap = 1;
    for (int y = 1; y <= n; y++) {
      int cnt = 0;
      for (int z = 0; z < m; z++) {
        if (a[vt[i].second][z] > a[y][z]) cnt++;
      }
      if (cnt == m) {
        gap = max(dp[y] + 1, gap);
      }
    }
    dp[vt[i].second] = gap;
    dap = max(dap, gap);
  }
  printf("%d", dap);
}
