#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const long long oo = 1e9 + 7;
struct kaka {
  long long a, b, c;
} x[N];
long long n, m;
long long calc(long long u, long long v, long long k) {
  long long res = min(x[u].a + x[v].b + x[k].c, x[u].a + x[k].b + x[v].c);
  res = min(res, x[v].a + x[u].b + x[k].c);
  res = min(res, x[v].a + x[k].b + x[u].c);
  res = min(res, x[k].a + x[u].b + x[v].c);
  res = min(res, x[k].a + x[v].b + x[u].c);
  return res;
}
int main() {
  cin >> n >> m;
  for (long long t = 1; t <= n; t++) {
    string s;
    cin >> s;
    x[t].a = x[t].b = x[t].c = oo;
    for (long long i = 0; i < m; i++) {
      if (s[i] == '*' || s[i] == '#' || s[i] == '&')
        x[t].c = min(x[t].c, min(i, m - i));
      else if (s[i] >= '0' && s[i] <= '9')
        x[t].b = min(x[t].b, min(i, m - i));
      else
        x[t].a = min(x[t].a, min(i, m - i));
    }
  }
  long long res = oo;
  for (long long u = 1; u <= n; u++) {
    for (long long v = u + 1; v <= n; v++) {
      for (long long k = v + 1; k <= n; k++) res = min(res, calc(u, v, k));
    }
  }
  cout << res << endl;
}
