#include <bits/stdc++.h>
using namespace std;
int M, N;
char t[110][110];
bool e[110];
int det(int u, int n) {
  for (int i = 1; i <= N; i++) {
    if (e[i]) continue;
    if (t[u][i] > t[n][i]) return i;
    if (t[u][i] < t[n][i]) return 0;
  }
  return 0;
}
int main() {
  cin >> M >> N;
  for (int i = 1; i <= M; i++)
    for (int j = 1; j <= N; j++) cin >> t[i][j];
  for (int k = 1; k <= N + 1; k++) {
    bool flag = true;
    for (int i = M; i > 1; i--) {
      int d = det(i - 1, i);
      if (d) {
        e[d] = true;
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << k - 1;
      return 0;
    }
  }
  return 0;
}
