#include <bits/stdc++.h>
using namespace std;
int counter;
int main(int argc, const char* argv[]) {
  int i, j, n, m, prevcol;
  string S[100];
  bool rowclear[100];
  counter = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    rowclear[i] = 0;
    cin >> S[i];
  }
  int flag = 0;
  prevcol = -1;
  for (j = 0; j < m; j++) {
    flag = 0;
    bool flag2 = 0;
    for (i = 0; i < n - 1; i++) {
      if (rowclear[i] == 1) continue;
      if (prevcol == -1) {
        if (S[i][j] < S[i + 1][j])
          continue;
        else if (S[i][j] == S[i + 1][j]) {
          flag2 = 1;
          continue;
        } else {
          flag2 = 1;
          flag = 1;
          break;
        }
      } else {
        if (S[i][j] < S[i + 1][j])
          continue;
        else if (S[i][j] == S[i + 1][j]) {
          flag2 = 1;
          continue;
        } else {
          flag2 = 1;
          if (S[i][prevcol] == S[i + 1][prevcol]) {
            flag = 1;
            break;
          } else
            continue;
        }
      }
    }
    if (flag == 0) {
      prevcol = j;
      for (i = 0; i < n - 1; i++) {
        if (S[i][j] < S[i + 1][j]) rowclear[i] = 1;
      }
    } else if (flag == 1)
      counter++;
    if (flag2 == 0) {
      break;
    }
  }
  cout << counter << "\n";
  return 0;
}
