#include <bits/stdc++.h>
using namespace std;
string arr[150], e[150];
long long n, m;
bool isinc(int i) {
  for (int j = 1; j < n; j++) {
    if (arr[j][i] < arr[j - 1][i]) return false;
  }
  return true;
}
bool isinc1(int i) {
  for (int j = 1; j < n; j++) {
    if (arr[j][i] < arr[j - 1][i]) {
      if (e[j] == e[j - 1]) return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long cnt = 0, cnt1 = 0;
  for (int j = 0; j < m; j++) {
    if (cnt1 == 0) {
      if (isinc(j)) {
        cnt1++;
        for (int i = 0; i < n; i++) {
          e[i] += arr[i][j];
        }
      } else
        cnt++;
    } else {
      if (isinc1(j)) {
        for (int i = 0; i < n; i++) {
          e[i] += arr[i][j];
        }
      } else
        cnt++;
    }
  }
  cout << cnt;
  return 0;
}
