#include <bits/stdc++.h>
using namespace std;
const int dr[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dc[] = {0, 0, 1, -1, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e5 + 5;
const long double pi = acos(-1);
const double eps = 1e-9;
int n, m, cnt, bef, sz;
string s[105], tmp[105];
bool flag, head, flag2;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (long long j = 0; j < m; j++) {
    flag = 0;
    for (long long i = 2; i <= n; i++) {
      if (head) {
        flag2 = 0;
        if (s[i][j] < s[i - 1][j]) {
          if (tmp[i] == tmp[i - 1]) {
            flag = 1;
          }
        }
      } else {
        if (s[i][j] < s[i - 1][j]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      cnt++;
    } else {
      head = 1;
      for (long long i = 1; i <= n; i++) {
        tmp[i] += s[i][j];
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}
