#include <bits/stdc++.h>
int minimum(int a, int b);
int main() {
  int n, m;
  char digits[50][51];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", digits[i]);
  int ans = 1000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (i == j || i == k || j == k) continue;
        int a = 1000, b = 1000, c = 1000;
        for (int p = 0; p < m; p++) {
          if ('0' <= digits[i][p] && digits[i][p] <= '9')
            a = minimum(a, minimum(p, m - p));
        }
        for (int p = 0; p < m; p++) {
          if ('a' <= digits[j][p] && digits[j][p] <= 'z')
            b = minimum(b, minimum(p, m - p));
        }
        for (int p = 0; p < m; p++) {
          if (digits[k][p] == '#' || digits[k][p] == '*' || digits[k][p] == '&')
            c = minimum(c, minimum(p, m - p));
        }
        ans = minimum(ans, a + b + c);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
int minimum(int a, int b) { return a < b ? a : b; }
