#include <bits/stdc++.h>
using namespace std;
void scanint(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
int cmp(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j, k;
  cin >> n >> m;
  int a[n][3];
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) {
      a[i][j] = 55;
    }
  }
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (j = 0; j < m; j++) {
      int ctr = 2;
      if (s[j] == '#' || s[j] == '*' || s[j] == '&')
        ctr = 0;
      else if (s[j] >= '0' && s[j] <= '9')
        ctr = 1;
      if (a[i][ctr] > min(j, m - j)) a[i][ctr] = min(j, m - j);
    }
  }
  int ans = 200;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (i == j) continue;
      for (k = 0; k < n; k++) {
        if (i == k || k == j) continue;
        ans = min(ans, a[i][0] + a[j][1] + a[k][2]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
