#include <bits/stdc++.h>
using namespace std;
const double eps = 0.0000001;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
char str[100][105];
int num[105][3];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i]);
  memset(num, inf, sizeof(num));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] >= 'a' && str[i][j] <= 'z') {
        int dd = min(j, m - j);
        num[i][0] = min(num[i][0], dd);
      }
      if (str[i][j] >= '0' && str[i][j] <= '9') {
        int dd = min(j, m - j);
        num[i][1] = min(num[i][1], dd);
      }
      if (str[i][j] == '#' || str[i][j] == '*' || str[i][j] == '&') {
        int dd = min(j, m - j);
        num[i][2] = min(num[i][2], dd);
      }
    }
  }
  int ans = inf;
  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 || num[i][0] == inf ||
            num[j][1] == inf || num[k][2] == inf)
          continue;
        ans = min(ans, num[i][0] + num[j][1] + num[k][2]);
      }
    }
  }
  printf("%d\n", ans);
}
