#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T& x) {
  return x * x;
}
template <class T>
inline void updMin(T& a, const T& b) {
  if (b < a) a = b;
}
template <class T>
inline void updMax(T& a, const T& b) {
  if (b > a) a = b;
}
int n, m;
char s[2000][2000];
bool used[2000];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  int ans = 0;
  int ch = 0;
  do {
    ch = 0;
    for (int i = n - 2; i >= 0; i--) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] > s[i + 1][j] && !used[j]) {
          used[j] = 1;
          ans++;
          ch++;
        } else if (s[i][j] < s[i + 1][j] && !used[j]) {
          break;
        }
      }
    }
  } while (ch > 0);
  printf("%d\n", ans);
  return 0;
}
