#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, count = 0;
  bool temp = true;
  cin >> n >> m;
  string s[101];
  vector<int> v(101);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    temp = true;
    for (int j = 0; j < n - 1; j++) {
      if (s[j][i] > s[j + 1][i] && v[j] != 1) {
        temp = false;
        count++;
        break;
      }
    }
    if (temp == true) {
      for (int k = 0; k < n - 1; k++) {
        if (s[k][i] < s[k + 1][i]) {
          v[k] = 1;
        }
      }
    }
  }
  cout << count;
  return 0;
}
