#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const double PI = 3.14159265;
int res = inf;
int k[50][3];
int N;
void deep(int pos, int s, int isS, int isN, int isD) {
  if (pos == N) {
    if (isS && isN && isD) {
      res = min(res, s);
    }
    return;
  }
  if (isS && isN && isD) {
    deep(pos + 1, s + min(k[pos][0], min(k[pos][1], k[pos][2])), isS, isN, isD);
  }
  if (k[pos][0] != 500) {
    deep(pos + 1, s + k[pos][0], 1, isN, isD);
  }
  if (k[pos][1] != 500) {
    deep(pos + 1, s + k[pos][1], isS, 1, isD);
  }
  if (k[pos][2] != 500) {
    deep(pos + 1, s + k[pos][2], isS, isN, 1);
  }
}
int main() {
  int S;
  string str;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    cin >> str;
    int toS = 500, toN = 500, toD = 500;
    for (int j = 0; j < S; j++) {
      if (str[j] >= 'a' && str[j] <= 'z') {
        toS = min(toS, min(j, S - j));
      }
      if (str[j] >= '0' && str[j] <= '9') {
        toN = min(toN, min(j, S - j));
      }
      if (str[j] == '#' || str[j] == '*' || str[j] == '&') {
        toD = min(toD, min(j, S - j));
      }
    }
    k[i][0] = toS;
    k[i][1] = toN;
    k[i][2] = toD;
  }
  int mn = 5000;
  for (int f = 0; f < N; f++) {
    for (int s = 0; s < N; s++) {
      for (int t = 0; t < N; t++) {
        if (f != s && f != t && s != t) {
          mn = min(mn, k[f][0] + k[s][1] + k[t][2]);
        }
      }
    }
  }
  cout << mn;
}
