#include <bits/stdc++.h>
using namespace std;
int n, m;
bool f[111];
string arr[111];
int main(int argc, char **argv) {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  int cnt = 0, prev = m;
  for (int j = 0; j < m; ++j) {
    bool f = 1;
    for (int i = 1; i < n; ++i) {
      if (arr[i].substr(0, j + 1) < arr[i - 1].substr(0, j + 1)) {
        ++cnt;
        for (int i = 0; i < n; ++i) arr[i][j] = 'z';
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
