#include <bits/stdc++.h>
using namespace std;
void print_array(int[], int);
char myList[105][105];
int main() {
  int r, c;
  cin >> r >> c;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> myList[i][j];
    }
  }
  int ans = 0;
  const int size = r - 1;
  int L[size];
  memset(L, 0, sizeof L);
  for (int i = 0; i < c; ++i) {
    int T[size];
    memset(T, 0, sizeof T);
    for (int k = 1; k < r; ++k) {
      if (myList[k][i] < myList[k - 1][i]) {
        if (ans == i) {
          ans++;
          goto next;
        } else if (L[k - 1] == 0) {
          ans++;
          goto next;
        }
      } else if (myList[k][i] == myList[k - 1][i]) {
        T[k - 1] = 0;
      } else
        T[k - 1] = 1;
    }
    for (int i = 0; i < size; ++i) {
      L[i] |= T[i];
    }
  next:;
  }
  cout << ans << endl;
  return 0;
}
void print_array(int A[], int len) {
  for (int i = 0; i < len; ++i) {
    cout << A[i];
  }
  cout << endl;
}
