#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[100][101];
bool flag[100];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 0; i < m; i++) flag[i] = true;
  int res = 0;
  for (int col = 0; col < m; col++) {
    bool f = true;
    for (int i = 0; i < n - 1; i++) {
      for (int pos = 0; pos <= col; pos++)
        if (flag[pos]) {
          if (str[i][pos] != str[i + 1][pos]) {
            if (str[i][pos] > str[i + 1][pos]) {
              f = false;
              break;
            }
            break;
          }
        }
      if (!f) break;
    }
    if (!f) {
      flag[col] = false;
      res++;
    }
  }
  cout << res << endl;
  return 0;
}
