#include <bits/stdc++.h>
using namespace std;
string arr[105];
bool tbd[105];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  while (1) {
    bool change = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < m; j++) {
        if (tbd[j]) continue;
        if (arr[i][j] < arr[i + 1][j])
          break;
        else if (arr[i][j] > arr[i + 1][j])
          tbd[j] = 1, change = 1;
      }
    }
    if (!change) break;
  }
  int res = 0;
  for (int i = 0; i < m; i++) res += tbd[i];
  cout << res;
  return 0;
}
