#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
char mat[maxn][maxn];
bool flag[maxn];
int main() {
  int n, m, ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mat[i]);
  for (int j = 0; j < m; ++j) {
    bool mark = 0;
    for (int i = 1; i < n; ++i) {
      if (flag[i]) continue;
      if (mat[i][j] < mat[i - 1][j]) {
        mark = 1;
        break;
      }
    }
    if (mark == 1) {
      ++ans;
      continue;
    }
    for (int i = 1; i < n; ++i) {
      if (flag[i]) continue;
      if (mat[i][j] > mat[i - 1][j]) {
        flag[i] = 1;
        continue;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
