#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1E-6;
const int LEN = 55;
string pwd[LEN];
int n, m, dp[LEN][8], near[LEN][3];
int gc(char c) {
  if (c >= '0' && c <= '9')
    return 0;
  else if (c >= 'a' && c <= 'z')
    return 1;
  else
    return 2;
}
void calc(int p) {
  string str = pwd[p];
  for (int i = 0; i < str.size(); i++) {
    int k = gc(str[i]);
    near[p][k] = min(near[p][k], i);
    near[p][k] = min(near[p][k], (int)str.size() - i);
  }
}
int main() {
  while (cin >> n >> m) {
    memset(dp, INF, sizeof dp);
    memset(near, INF, sizeof near);
    for (int i = 1; i <= n; i++) cin >> pwd[i];
    for (int i = 1; i <= n; i++) calc(i);
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < i; j++) {
        for (int k = 0; k < 8; k++) dp[i][k] = min(dp[i][k], dp[j][k]);
        for (int k = 0; k < 3; k++)
          if (near[i][k] != INF) {
            for (int a = 0; a < 8; a++) {
              dp[i][a | (1 << k)] =
                  min(dp[i][a | (1 << k)], dp[j][a] + near[i][k]);
            }
          }
      }
    }
    cout << dp[n][7] << endl;
  }
  return 0;
}
