#include <bits/stdc++.h>
using namespace std;
int used[1123], used1[1123];
char a[1123][1123];
int main() {
  int n, m, i, j;
  bool flag = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (j = 1; j <= m; j++) {
    flag = 0;
    for (i = 2; i <= n; i++) {
      if (used[i] == 0) {
        if (a[i][j] < a[i - 1][j]) {
          ans++;
          flag = 1;
          break;
        } else if (a[i][j] > a[i - 1][j]) {
          used1[i] = 1;
        }
      } else {
        used1[i] = 1;
      }
    }
    if (flag == 0) {
      for (i = 2; i <= n; i++) {
        used[i] = used1[i];
      }
    }
    for (i = 2; i <= n; i++) {
      used1[i] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
