#include <bits/stdc++.h>
using namespace std;
string cade[1000], sum;
string T[1000], T1[1000];
int n, m;
bool v[1000], nv[1000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> cade[i];
  }
  int con = 0;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) T1[i] = T[i];
    T1[0] += cade[0][j];
    bool yes = true;
    for (int i = 1; i < n; i++) {
      T1[i] += cade[i][j];
      if (T1[i] < T1[i - 1]) {
        yes = false;
        con++;
        break;
      }
    }
    if (yes == true) {
      for (int i = 0; i < n; i++) T[i] = T1[i];
    }
  }
  cout << con << endl;
}
