#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
bool mrk[MAXN];
char arr[MAXN][MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  for (int x = 0; x < n * n; x++) {
    bool h = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < m; j++) {
        if (mrk[j]) continue;
        if (arr[i][j] < arr[i + 1][j]) break;
        if (arr[i + 1][j] < arr[i][j]) {
          mrk[j] = 1;
          h = 1;
        }
      }
    }
    if (!h) break;
  }
  int cnt = 0;
  for (int i = 0; i < m; i++)
    if (mrk[i]) cnt++;
  cout << cnt << endl;
  return 0;
}
