#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXM = 2e6 + 5;
int n, m;
string s[105];
int vis[105];
int main() {
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) cin >> s[i];
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    for (int j = 0; j <= m - 1; j++) {
      int flag = 0;
      for (int i = 2; i <= n; i++) {
        if (vis[i]) continue;
        if (s[i - 1][j] > s[i][j]) {
          flag = 1;
          break;
        }
      }
      if (flag) {
        ans++;
      } else {
        for (int i = 2; i <= n; i++) {
          if (vis[i]) continue;
          if (s[i - 1][j] < s[i][j]) {
            vis[i] = 1;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
