#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  int arr[m];
  fill(arr, arr + m, 0);
  int prev_t = -1, prev_l = -1;
  int i, j;
  for (j = 0; j < m; j++) {
    for (i = 1; i < n; i++) {
      if (a[i][j] < a[i - 1][j]) {
        if (prev_t == -1) {
          prev_l++;
          arr[prev_l] = -1;
          break;
        } else {
          int x;
          for (x = 0; x < j; x++) {
            if (arr[x] == -1) continue;
            if (a[i][x] != a[i - 1][x]) break;
          }
          if (x == j) {
            prev_l = j;
            arr[j] = -1;
            break;
          }
        }
      }
    }
    if (i == n) prev_t = j;
    if (arr[j] == -1) ans++;
  }
  cout << ans;
}
