#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[105][105];
int mark[105], vis[105];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> (a[i] + 1);
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int k = 0;
    for (int j = 1; j < n; j++) {
      if (mark[j] == 1) continue;
      if (a[j + 1][i] < a[j][i]) k = 1;
    }
    if (k == 1)
      vis[i] = 1;
    else {
      for (int j = 1; j < n; j++) {
        if (a[j + 1][i] > a[j][i]) mark[j] = 1;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (vis[i] == 1) ans++;
  }
  cout << ans;
  return 0;
}
