#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
char s[110][110];
int a[110][110];
int f[110];
vector<int> vt;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = s[i][j] - 'a';
    }
  }
  int ans = 0;
  int k = 1;
  f[1] = n;
  for (int i = 1; i <= m; i++) {
    vt.clear();
    int s = 0, flag = 0;
    for (int r = 1; r <= k; r++) {
      s += f[r];
      for (int ii = s - f[r] + 1; ii < s; ii++) {
        if (a[ii][i] > a[ii + 1][i]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      ans++;
      continue;
    }
    s = 0;
    for (int r = 1; r <= k; r++) {
      s += f[r];
      int L = s - f[r] + 1, R = s;
      int nn = 1;
      for (int ii = L + 1; ii <= R; ii++) {
        if (a[ii][i] == a[ii - 1][i])
          nn++;
        else {
          vt.push_back(nn);
          nn = 1;
        }
      }
      vt.push_back(nn);
    }
    k = vt.size();
    for (int ii = 1; ii <= k; ii++) f[ii] = vt[ii - 1];
  }
  printf("%d\n", ans);
  return 0;
}
