#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, i, j, k, q, s, w, v, ans;
string t[1010];
bool mark[1010];
bool dep[1010];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> t[i];
  int lrem = -1;
  for (j = 0; j < m; j++) {
    for (i = 1; i < n; i++) {
      if (t[i][j] > t[i + 1][j]) {
        mark[j] = 1;
        break;
      }
    }
    if (mark[j] == 0) {
      s = j;
      break;
    }
  }
  for (i = 1; i < n; i++)
    if (t[i][s] == t[i + 1][s]) dep[i] = 1;
  s++;
  for (j = s; j < m; j++) {
    for (i = 1; i < n; i++) {
      if (dep[i] == 0)
        continue;
      else {
        if (t[i][j] > t[i + 1][j]) {
          mark[j] = 1;
          goto verj;
        }
      }
    }
    for (i = 1; i < n; i++) {
      if (dep[i] == 0)
        continue;
      else {
        if (t[i][j] < t[i + 1][j]) dep[i] = 0;
      }
    }
  verj:;
  }
  for (i = 0; i < m; i++)
    if (mark[i] == 1) q++;
  cout << q << endl;
  return 0;
}
