#include <bits/stdc++.h>
using namespace std;
int n, m;
char mat[110][110];
bool need[110];
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  memset(need, 1, sizeof(need));
  int ans = 0;
  for (int j = 0; j < m; j++) {
    bool rem = false;
    vector<int> chg;
    for (int i = 0; i < n - 1 && !rem; i++) {
      if (need[i] && mat[i][j] > mat[i + 1][j])
        rem = true;
      else if (need[i] && mat[i][j] < mat[i + 1][j])
        chg.push_back(i);
    }
    if (rem)
      ans++;
    else {
      for (int j = 0; j < chg.size(); j++) {
        need[chg[j]] = false;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
