#include <bits/stdc++.h>
using namespace std;
int main() {
  int V[110];
  int ans = 0, oldans;
  memset(V, -1, sizeof(V));
  char a[110][110];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < m; i++) {
    oldans = ans;
    int cnt = 1;
    for (int j = 1; j < n; j++) {
      if (V[i] != -1) continue;
      if (a[j][i] < a[j - 1][i]) {
        V[i] = false;
        ans++;
        break;
      } else if (a[j][i] == a[j - 1][i]) {
        int idx = i;
        while (idx < m &&
               ((a[j][idx] <= a[j - 1][idx] && V[idx] == -1) || V[idx] != -1)) {
          if (a[j][idx] < a[j - 1][idx] && V[idx] == -1) {
            V[idx] = false;
            ans++;
          }
          idx++;
        }
        if (oldans < ans) {
          i--;
          break;
        }
        cnt++;
      } else
        cnt++;
    }
    if (cnt == n) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
