#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int INF = 1e9;
int n, m;
char mt[N][N];
int p[N][3];
set<pair<int, int> > st[3];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mt[i]);
  for (int i = 0; i < n; ++i) {
    int a1 = INF, a2 = INF, a3 = INF;
    for (int j = 0; j < m; ++j) {
      if (mt[i][j] >= '0' and mt[i][j] <= '9')
        a1 = min(a1, min(j, m - j));
      else if (mt[i][j] >= 'a' and mt[i][j] <= 'z')
        a2 = min(a2, min(j, m - j));
      else
        a3 = min(a3, min(j, m - j));
    }
    st[0].emplace(a1, i);
    st[1].emplace(a2, i);
    st[2].emplace(a3, i);
  }
  vector<int> v = {0, 1, 2};
  int ans = INF;
  do {
    set<int> s;
    int cur = 0;
    int in = 0;
    for (int i : v) {
      bool ok = false;
      for (auto j : st[i]) {
        if (!s.count(j.second)) {
          s.emplace(j.second);
          cur += j.first;
          ok = true;
          break;
        }
      }
      if (ok) in++;
    }
    if (in < 3) continue;
    ans = min(ans, cur);
  } while (next_permutation(v.begin(), v.end()));
  printf("%d\n", ans);
  return 0;
}
