#include <bits/stdc++.h>
using namespace std;
int N, M, K, T;
string s[100];
int symcost[100], digitcost[100], alphacost[100];
bool isdigit(char x) {
  if (x >= '0' && x <= '9') return true;
  return false;
}
bool isalpha(char x) {
  if (x >= 'a' && x <= 'z') return true;
  return false;
}
bool issymbol(char x) {
  if (x == '#' || x == '*' || x == '&') return true;
  return false;
}
int main(void) {
  scanf("%d%d", &N, &M);
  bool digit = false, alpha = false, symbol = false;
  for (int i = 0; i < 100; i++) {
    symcost[i] = digitcost[i] = alphacost[i] = 1000000;
  }
  for (int i = 1; i <= N; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) {
      int cost = min(j, (int)s[i].size() - j);
      if (isalpha(s[i][j])) alphacost[i] = min(alphacost[i], cost);
      if (isdigit(s[i][j])) digitcost[i] = min(digitcost[i], cost);
      if (issymbol(s[i][j])) symcost[i] = min(symcost[i], cost);
    }
  }
  int ans = 987654321;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        if (i == j || j == k || i == k) continue;
        ans = min(ans, alphacost[i] + digitcost[j] + symcost[k]);
      }
    }
  }
  cout << ans;
}
