#include <bits/stdc++.h>
using namespace std;
char s[105][105];
int a[105];
int main() {
  int n, m, cot = 0, flag = 0, num = 1;
  a[0] = num;
  num++;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> s[i][j];
    }
  }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i < n; i++) {
      if (s[i][j] > s[i + 1][j]) {
        if (a[j - 1] == j) {
          cot++;
          a[j] = num;
          num++;
          break;
        } else {
          for (int k = 0; k < j; k++) {
            if (!a[k]) {
              if (s[i][k] < s[i + 1][k]) {
                break;
              }
            }
            if (k == j - 1) {
              cot++;
              a[j] = num;
              num++;
            }
          }
        }
      }
      if (a[j]) break;
    }
  cout << cot;
}
