#include <bits/stdc++.h>
using namespace std;
const int inf = 100000;
int main(void) {
  int n, m, i, j, k, l;
  char a[100][100];
  while (scanf("%d%d", &n, &m) == 2) {
    for (i = 0; i < n; i++) scanf("%s", a[i]);
    int minn = inf;
    for (i = 0; i < n; i++)
      for (j = i + 1; j < n; j++)
        for (k = j + 1; k < n; k++) {
          int x[3], y[3], z[3];
          memset(x, 0x1f, sizeof(x));
          memset(y, 0x1f, sizeof(y));
          memset(z, 0x1f, sizeof(z));
          for (l = 0; l < m; l++) {
            if (a[i][l] >= '0' && a[i][l] <= '9')
              x[0] = min(x[0], min(l, m - l));
            if (a[i][l] >= 'a' && a[i][l] <= 'z')
              x[1] = min(x[1], min(l, m - l));
            if (a[i][l] == '#' || a[i][l] == '*' || a[i][l] == '&')
              x[2] = min(x[2], min(l, m - l));
            if (a[j][l] >= '0' && a[j][l] <= '9')
              y[0] = min(y[0], min(l, m - l));
            if (a[j][l] >= 'a' && a[j][l] <= 'z')
              y[1] = min(y[1], min(l, m - l));
            if (a[j][l] == '#' || a[j][l] == '*' || a[j][l] == '&')
              y[2] = min(y[2], min(l, m - l));
            if (a[k][l] >= '0' && a[k][l] <= '9')
              z[0] = min(z[0], min(l, m - l));
            if (a[k][l] >= 'a' && a[k][l] <= 'z')
              z[1] = min(z[1], min(l, m - l));
            if (a[k][l] == '#' || a[k][l] == '*' || a[k][l] == '&')
              z[2] = min(z[2], min(l, m - l));
          }
          for (int t1 = 0; t1 < 3; t1++)
            for (int t2 = 0; t2 < 3; t2++) {
              if (t2 == t1) continue;
              for (int t3 = 0; t3 < 3; t3++) {
                if (t3 == t2 || t3 == t1) continue;
                minn = min(minn, x[t1] + y[t2] + z[t3]);
              }
            }
        }
    cout << minn << endl;
  }
  return 0;
}
