#include <bits/stdc++.h>
using namespace std;
int b, bb;
int main() {
  string s[1000];
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n - 1;) {
    if (s[i] > s[i + 1]) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] > s[i + 1][j]) {
          for (int k = 0; k < n; k++) s[k][j] = ' ';
          ans++;
          i = 0;
          break;
        }
      }
    } else
      i++;
  }
  cout << ans;
  return 0;
}
