#include <bits/stdc++.h>
using namespace std;
char a[55][55];
typedef struct node {
  int n1;
  int n2;
} node;
node no1[3000];
node no2[3000];
node no3[3000];
int nn1, nn2, nn3;
bool cmp(node x, node y) { return x.n2 < y.n2; }
int main() {
  int n, m;
  int i, j, k;
  int b, c, d;
  int ans, temp;
  while (~scanf("%d%d", &n, &m)) {
    nn1 = nn2 = nn3 = 0;
    for (i = 0; i < n; i++) {
      scanf("%s", &a[i]);
      for (j = 0; j < m; j++) {
        if (a[i][j] >= '0' && a[i][j] <= '9') {
          no1[nn1].n1 = i;
          if (j > m - j)
            no1[nn1++].n2 = m - j;
          else
            no1[nn1++].n2 = j;
        } else if (a[i][j] >= 'a' && a[i][j] <= 'z') {
          no2[nn2].n1 = i;
          if (j > m - j)
            no2[nn2++].n2 = m - j;
          else
            no2[nn2++].n2 = j;
        } else if ((a[i][j] == '#' || a[i][j] == '*' || a[i][j] == '&')) {
          no3[nn3].n1 = i;
          if (j > m - j)
            no3[nn3++].n2 = m - j;
          else
            no3[nn3++].n2 = j;
        }
      }
    }
    sort(no1, no1 + nn1, cmp);
    sort(no2, no2 + nn2, cmp);
    sort(no3, no3 + nn3, cmp);
    ans = 100000;
    for (i = 0; i < nn1; i++)
      for (j = 0; j < nn2; j++)
        for (k = 0; k < nn3; k++) {
          if (no1[i].n1 != no2[j].n1 && no1[i].n1 != no3[k].n1 &&
              no2[j].n1 != no3[k].n1) {
            temp = no1[i].n2 + no2[j].n2 + no3[k].n2;
            if (ans > temp) ans = temp;
          }
        }
    printf("%d\n", ans);
  }
  return 0;
}
