#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char s[N][N];
vector<char> v[N];
int f[N] = {0};
int main(int argc, char** argv) {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int ret = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      v[j].push_back(s[j][i]);
    }
    int k = 0;
    for (int j = 0; j < n - 1; ++j) {
      if (v[j] > v[j + 1]) {
        k = 1;
      }
    }
    if (k == 1) {
      for (int j = 0; j < n; ++j) v[j].pop_back();
      ret += 1;
    }
  }
  cout << ret << endl;
  return 0;
}
