#include <bits/stdc++.h>
using namespace std;
int n, m;
char maze[110][110];
string words[110], twords[110];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    words[i] = "";
    for (int j = 1; j <= m; j++) {
      cin >> maze[i][j];
    }
  }
  int br = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      twords[i] = words[i] + maze[i][j];
    }
    bool check = true;
    for (int i = 1; i + 1 <= n; i++) {
      if (twords[i] > twords[i + 1]) check = false;
    }
    if (check) {
      for (int i = 1; i <= n; i++) words[i] = twords[i];
    } else
      br++;
  }
  cout << br;
  return 0;
}
