#include <bits/stdc++.h>
using namespace std;
int n, m;
char table[1001][1001];
bool diff[1001];
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> table[i][j];
    }
  }
  int nDel = 0;
  for (int j = 0; j < m; j++) {
    bool valid = true;
    for (int i = 1; i < n; i++) {
      if (!(table[i][j] >= table[i - 1][j] or diff[i])) {
        valid = false;
      }
    }
    if (valid) {
      for (int i = 1; i < n; i++) {
        if (table[i][j] > table[i - 1][j]) diff[i] = true;
      }
    }
    if (!valid) nDel++;
  }
  cout << nDel;
}
