#include <fstream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>

#define oo (1000000000)

using namespace std;

typedef vector <string> tVec;
typedef set <char> tSet;

#define in cin
int n, l;

int main() {
  while (1) {
    tVec words;

    in >> n >> l;
    if (!n && !l)
      break;

    for (int i=0; i<n; i++) {
      string s;
      in >> s;
      words.push_back(s);
    }

    int sum = 0;
    for (int i=0; i<l; i++) {     // Jeder Buchstabe einzeln
      int h[2048][256];
      tSet myset;                 // alle Buchstaben, die vorkommen
      
      for (int j = 0; j<n; j++) 
	myset.insert(words[j][i]);
      
      for (int j = 0; j<n; j++)
	for (int k = 'A'; k <= 'Z'; k++) {
	  h[j+n][k] = (words[j][i] == k)?0:1;
	  //  cout << "h[" << j << "][" << k << "] = " << h[j][k] << endl;
	}
    
      for (int j = n-1; j>=n/2; j--)
	for (int k = 'A'; k <= 'Z'; k++) {
	  h[j][k] = (h[2*j][k]==0?0:1) + (h[2*j+1][k]==0?0:1);
	  //  cout << "h[" << j << "][" << k << "] = " << h[j][k] << endl;
	}
	  
      for (int j = n/2-1; j>0; j--) {
	int leftmin = oo;
	for (int l='A'; l <= 'Z'; l++)
	  leftmin = min(leftmin, h[2*j][l]);
	int rightmin = oo;
	for (int l='A'; l <= 'Z'; l++)
	  rightmin = min(rightmin, h[2*j+1][l]);
	for (int k = 'A'; k <= 'Z'; k++) {
	  int left  = min(h[2*j][k],   leftmin+1);
	  int right = min(h[2*j+1][k], rightmin+1);
	  h[j][k] = left + right;
	  //  cout << "h[" << j << "][" << k << "] = " << h[j][k] << endl;
	}
	
      }
      int minimum = oo;
      char c ;
      for (int k = 'A'; k <= 'Z'; k++)
	if (h[1][k] < minimum && myset.find(k) != myset.end()) {
	  c = k;
	  minimum = h[1][k];
	}
      cout << c;
      sum += minimum;
    }
    cout << " " << sum << endl;
  }
  return 0;
}

