#include <bits/stdc++.h>
using namespace std;
string s[60];
typedef struct point {
  int x = 100, y = 100;
} Point;
Point dig[3000];
Point low[3000];
Point xx[3000];
bool cmp(Point a, Point b) {
  if (a.y != b.y)
    return a.y < b.y;
  else
    return a.x < b.x;
}
int main() {
  int n, m;
  scanf("%d%d\n", &n, &m);
  int aa = 0, bb = 0, cc = 0;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      if (isdigit(s[i][j])) {
        if (j > m / 2) {
          dig[aa].x = i;
          dig[aa++].y = m - j;
        } else {
          dig[aa].x = i;
          dig[aa++].y = j;
        }
      }
    }
    for (int j = 0; j < m; j++) {
      if (islower(s[i][j])) {
        if (j > m / 2) {
          low[bb].x = i;
          low[bb++].y = m - j;
        } else {
          low[bb].x = i;
          low[bb++].y = j;
        }
      }
    }
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*' || s[i][j] == '&' || s[i][j] == '#') {
        if (j > m / 2) {
          xx[cc].x = i;
          xx[cc++].y = m - j;
        } else {
          xx[cc].x = i;
          xx[cc++].y = j;
        }
      }
    }
  }
  sort(low, low + aa, cmp);
  sort(dig, dig + bb, cmp);
  sort(xx, xx + cc, cmp);
  for (int i = 0; i < aa; i++) {
    for (int j = 0; j < bb; j++) {
      for (int k = 0; k < cc; k++) {
        if (dig[i].x == low[j].x || dig[i].x == xx[k].x || low[j].x == xx[k].x)
          continue;
        else {
          printf("%d\n", dig[i].y + low[j].y + xx[k].y);
          return 0;
        }
      }
    }
  }
  return 0;
}
