#include <bits/stdc++.h>
inline int nextint(void) {
  int x;
  scanf("%d", &x);
  return (x);
}
inline void maximize(int &x, const int &y) {
  if (x < y) x = y;
}
int n, k, f[1111], p[1111][1111];
void init(void) {
  n = nextint();
  k = nextint();
  for (int i = 0, _n = (k); i < _n; i = i + 1)
    for (int j = (1), _b = (n); j <= _b; j = j + 1) p[nextint()][i] = j;
  memset(f, -1, sizeof f);
}
bool after(int x, int y) {
  for (int i = 0, _n = (k); i < _n; i = i + 1)
    if (p[x][i] >= p[y][i]) return (false);
  return (true);
}
int dp(int x) {
  if (f[x] > 0) return (f[x]);
  int &res = f[x];
  res = 1;
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    if (after(i, x)) maximize(res, dp(i) + 1);
  return (res);
}
void process(void) {
  int res = 0;
  for (int i = (1), _b = (n); i <= _b; i = i + 1) maximize(res, dp(i));
  printf("%d", res);
}
int main(void) {
  init();
  process();
  return 0;
}
