#include <bits/stdc++.h>
using namespace std;
struct sak {
  int a;
  int b;
};
sak AAAA[5009];
bool acompare(sak lhs, sak rhs) {
  if (lhs.a != rhs.a)
    return lhs.a < rhs.a;
  else
    return lhs.b < rhs.b;
}
char A[109][109];
int B[109];
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) == 2) {
    for (int i = 0; i < n; i++) {
      scanf("%s", A[i]);
      B[i] = 0;
    }
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      bool flag = false;
      for (int j = 1; j < n; j++)
        if (A[j][i] < A[j - 1][i] && B[j] == 0) {
          flag = true;
          break;
        }
      if (flag)
        cnt++;
      else {
        for (int j = 1; j < n; j++)
          if (A[j][i] > A[j - 1][i]) {
            B[j] = 1;
          }
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
