#include <bits/stdc++.h>
using namespace std;
string s[100];
queue<int> q1;
int main() {
  int row, colomn, total = 0;
  cin >> row >> colomn;
  for (int i = 0; i < row; i++) cin >> s[i];
  q1.push(0);
  q1.push(row - 1);
  int cur_colomn = 0;
  while (!q1.empty() && cur_colomn < colomn) {
    queue<int> q2, q3;
    q2 = q1;
    bool k = 1;
    while (!q2.empty()) {
      int begin = q2.front();
      q2.pop();
      int end = q2.front();
      q2.pop();
      for (int i = begin; i < end; i++)
        if (int(s[i][cur_colomn]) > int(s[i + 1][cur_colomn])) {
          k = 0;
          cur_colomn++;
          total++;
          break;
        }
      if (k) {
        for (int i = begin; i < end; i++)
          if (int(s[i][cur_colomn]) == int(s[i + 1][cur_colomn])) {
            int m = i;
            for (;
                 m < end && int(s[m][cur_colomn]) == int(s[m + 1][cur_colomn]);
                 m++)
              continue;
            q3.push(i);
            q3.push(m);
            i = m;
          }
      } else
        break;
    }
    if (k) {
      q1 = q3;
      cur_colomn++;
    }
  }
  cout << total << endl;
}
