#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e2 + 10;
int N, M, ans;
string S[maxN];
int check(int a, int b, int c) {
  int wa, wb, wc;
  wa = wb = wc = M;
  for (int i = 0; i < M; i++) {
    if (S[a][i] >= '0' && S[a][i] <= '9') wa = min(wa, min(i, M - i));
    if (S[b][i] >= 'a' && S[b][i] <= 'z') wb = min(wb, min(i, M - i));
    if (S[c][i] == '&' || S[c][i] == '#' || S[c][i] == '*')
      wc = min(wc, min(i, M - i));
  }
  return wa + wb + wc;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> S[i];
  ans = N * M;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++)
        if (i != j && j != k && k != i) ans = min(ans, check(i, j, k));
  cout << ans;
}
