public void solve() throws IOException {
    int n = nextInt();
    int m = nextInt();
    
    char[][] arr = new char[n][m];
    for (int x = 0; x < n; x++) {
      arr[x] = br.readLine().toCharArray();
    }
    
    Set<Integer> removed = new HashSet<Integer>();
    for (int y = 0; y < m; y++) {
      for (int x = 1; x < n; x++) {
        if (arr[x][y] < arr[x - 1][y]) {
          if (!search(arr, x, y, removed)) {
            removed.add(y);
            break;
          }
        }
      }
    }
    
    System.out.println(removed.size());
  }