#include <bits/stdc++.h>
using namespace std;
string s[1010];
int r[1010];
int main() {
  int a, b, c, m, n, e, d, ans;
  string k;
  for (c = 0; c < 1001; c++) {
    k = k + 'z';
  }
  while (scanf("%d %d", &n, &m) != EOF) {
    for (c = 0; c < 1010; c++) {
      s[c].clear();
    }
    for (c = 0; c < n; c++) {
      cin >> s[c];
    }
    s[n] = k;
    c = 0;
    ans = 0;
    while (1) {
      if (s[c + 1] >= s[c]) {
        c++;
      } else {
        for (d = 0; d < s[0].length(); d++) {
          if (s[c + 1][d] < s[c][d]) {
            ans++;
            for (e = 0; e < n; e++) {
              s[e].erase(s[e].begin() + d);
            }
            break;
          }
        }
        for (e = 0; e < n - 1; e++) {
          if (s[e + 1] < s[e]) {
            c = e;
            break;
          }
        }
      }
      if (c + 1 > n || s[0].length() == 0) {
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
