#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> data(n);
  for (int i = 0; i < n; ++i) {
    cin >> data[i];
  }
  int ans = 0;
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i < n; ++i) {
      string tmp1(data[i].begin(), data[i].begin() + j),
          tmp2(data[i - 1].begin(), data[i - 1].begin() + j);
      if (tmp2 > tmp1) {
        for (int k = 0; k < n; ++k) {
          data[k][j - 1] = 'a';
        }
        ++ans;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
