#include <bits/stdc++.h>
using namespace std;
char s[111][111];
string a[111];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; ++i) a[i] = "";
  for (int i = 0; i < n; ++i) scanf(" %s", s[i]);
  int cnt = 0;
  for (int j = 0; j < m; ++j) {
    int flag = 0;
    for (int i = 1; i < n; ++i) {
      string s1 = a[i - 1] + s[i - 1][j];
      string s2 = a[i] + s[i][j];
      if (s1 > s2) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cnt++;
    } else {
      for (int i = 0; i < n; ++i) a[i] += s[i][j];
    }
  }
  printf("%d\n", cnt);
}
