#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MIN;
long long mini = LLONG_MAX;
int main() {
  long long n, m;
  cin >> n >> m;
  long long d[n][m];
  char s[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
      d[i][j] = 0;
    }
  }
  long long ans = 0;
  if (n == 1) {
    cout << "0";
  } else {
    for (int i = 0; i < m; ++i) {
      for (int j = 1; j < n; ++j) {
        if (i != 0) {
          d[j][i] = d[j][i - 1];
        }
        if ((int)s[j][i] < (int)s[j - 1][i]) {
          if (i != 0) {
            if (d[j][i - 1] == 0) {
              ans++;
              j = n;
              for (int k = 0; k < n; ++k) {
                d[k][i] = d[k][i - 1];
              }
            }
          } else {
            ans++;
            j = n;
            for (int k = 0; k < n; ++k) {
              d[k][i] = 0;
            }
          }
        } else if ((int)s[j][i] > (int)s[j - 1][i]) {
          d[j][i] = 1;
        }
      }
    }
    cout << ans;
  }
  return 0;
}
