#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int N = 60;
char s[N][N];
int n, m;
int solve(int i, int j, int k) {
  int ret = 0, best;
  best = INF;
  for (int u = 0; u < m; ++u) {
    if (s[i][u] >= '0' && s[i][u] <= '9') {
      best = min(best, min(u, m - u));
    }
  }
  if (best == INF) return INF;
  ret += best;
  best = INF;
  for (int u = 0; u < m; ++u) {
    if (s[j][u] >= 'a' && s[j][u] <= 'z') {
      best = min(best, min(u, m - u));
    }
  }
  if (best == INF) return INF;
  ret += best;
  best = INF;
  for (int u = 0; u < m; ++u) {
    if (s[k][u] == '#' || s[k][u] == '*' || s[k][u] == '&') {
      best = min(best, min(u, m - u));
    }
  }
  if (best == INF) return INF;
  ret += best;
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  int ret = INF;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      for (int k = 0; k < n; ++k) {
        if (i == k || j == k) continue;
        ret = min(ret, solve(i, j, k));
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}
