#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[101];
  int valid[101];
  for (int i = 0; i < n; i++) {
    valid[i] = true;
    cin >> s[i];
  }
  int res = 0;
  for (int col = 0; col < m; col++) {
    bool flag = false;
    for (int row = 1; row < n; row++)
      if (valid[row])
        if (s[row][col] < s[row - 1][col]) {
          res++;
          flag = true;
          break;
        }
    if (flag) continue;
    for (int row = 1; row < n; row++)
      if (s[row][col] != s[row - 1][col]) valid[row] = false;
  }
  cout << res;
  return 0;
}
