#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> v, sol;
int main() {
  scanf("%d %d", &n, &m);
  v.resize(m);
  for (int i = 0; i < n; ++i) {
    char s[105];
    scanf("%s", s);
    for (int j = 0; j < m; ++j) {
      v[j].push_back(s[j]);
    }
  }
  sol.resize(n);
  for (int j = 0; j < v.size(); ++j) {
    bool ok = 1;
    for (int i = 1; i < v[j].size(); ++i) {
      if (sol[i - 1] + v[j][i - 1] > sol[i] + v[j][i]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      for (int i = 0; i < v[j].size(); ++i) {
        sol[i] = sol[i] + v[j][i];
      }
    }
  }
  printf("%d", m - sol[0].size());
  return 0;
}
