#include <bits/stdc++.h>
using namespace std;
vector<string> v;
string s;
bool flag = 0;
long long int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    cin >> s;
    v.push_back(s);
  }
  bool isok[1000], ok[1000];
  for (int i = 0; i < 1000; i++) {
    isok[i] = 0;
    ok[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    flag = 0;
    for (int j = 0; j < m - 1; j++) {
      if (v[j][i] > v[j + 1][i] && !ok[j + 1]) {
        isok[i] = 1;
        flag = 1;
        break;
      }
    }
    for (int j = 0; j < m - 1 && !flag; j++) {
      if (v[j][i] < v[j + 1][i] && !ok[j + 1]) {
        ok[j + 1] = 1;
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++)
    if (isok[i]) ans++;
  cout << ans;
  return 0;
}
