#include <bits/stdc++.h>
using namespace std;
string a[55];
int b[55], c[55], d[55];
int main() {
  int n, m, i, j, k, ans = 99999;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = 99999;
    c[i] = 99999;
    d[i] = 99999;
    for (j = 0; j < m; j++) {
      if (a[i][j] >= '0' && a[i][j] <= '9') b[i] = min(b[i], min(j, m - j));
      if (a[i][j] >= 'a' && a[i][j] <= 'z') c[i] = min(c[i], min(j, m - j));
      if (a[i][j] == '#' || a[i][j] == '*' || a[i][j] == '&')
        d[i] = min(d[i], min(j, m - j));
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        if (i != j && i != k && j != k) {
          ans = min(ans, b[i] + c[j] + d[k]);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
