#include <bits/stdc++.h>
using namespace std;
int n, m, mark[111], ans;
string s[111];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  memset(mark, 0, sizeof(mark));
  ans = 0;
  for (int col = 0; col < m; col++) {
    bool flag = false;
    for (int row = 1; row < n; row++)
      if (mark[row] == 0 && s[row][col] < s[row - 1][col]) flag = true;
    if (flag)
      ans++;
    else
      for (int row = 1; row < n; row++)
        if (mark[row] == 0 && s[row][col] != s[row - 1][col]) mark[row] = 1;
  }
  cout << ans;
  return 0;
}
