#include <bits/stdc++.h>   const int INF = 500000001;   const double EPS = 1e-9;   const double PI = acos(-1.0);   using namespace std;   int main() {     srand(time(NULL));     char ch[101][105];     int n, m;     int bl[105][105];     while (~scanf( %d %d , &n, &m)) {       for (int i = 0; i < n; i++) {         scanf( %s , ch[i]);       }       int ans = 0;       for (int j = 0; j < m; j++) {         int flag = 1;         bl[0][j] = 1;         for (int i = 1; i < n; i++) {           if (ch[i][j] < ch[i - 1][j] && (j == 0 || bl[i][j - 1] <= 1)) {             flag = 0;             break;           } else if (ch[i][j] == ch[i - 1][j] && (j == 0 || bl[i][j - 1] == 1)) {             bl[i][j] = 1;           } else if (j == 0 || bl[i][j - 1] >= 1) {             bl[i][j] = 2;           } else {             bl[i][j] = 0;           }         }         if (!flag) {           ++ans;           for (int i = 0; i < n; i++) {             ch[i][j] = ch[0][j];             if (j == 0)               bl[i][j] = 1;             else               bl[i][j] = bl[i][j - 1];           }         }       }       printf( %d n , ans);     }     return 0;   }   