#include <bits/stdc++.h>
using namespace std;
int n, m;
int const N = 50 + 3;
string pwd[N];
int alp[N];
int num[N];
int sym[N];
int balp = 1e9, bnum = 1e9, bsym = 1e9;
vector<pair<int, int>> palp;
vector<pair<int, int>> pnum;
vector<pair<int, int>> psym;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int asc, dist;
  for (int i = (0); i < (n); ++i) {
    cin >> pwd[i];
    alp[i] = num[i] = sym[i] = -1;
    for (int j = (0); j < (m); ++j) {
      asc = pwd[i][j];
      if (j > m / 2)
        dist = m - j;
      else
        dist = j;
      if (asc > 47 && asc < 58) {
        if (num[i] < 0)
          num[i] = dist;
        else
          num[i] = min(dist, num[i]);
        pnum.push_back({dist, i});
        sort(begin(pnum), end(pnum));
        if (int(pnum.size()) == 4) pnum.pop_back();
      } else if (asc > 96 && asc < 123) {
        if (alp[i] < 0)
          alp[i] = dist;
        else
          alp[i] = min(dist, alp[i]);
        palp.push_back({dist, i});
        sort(begin(palp), end(palp));
        if (int(palp.size()) == 4) palp.pop_back();
      } else {
        if (sym[i] < 0)
          sym[i] = dist;
        else
          sym[i] = min(dist, sym[i]);
        psym.push_back({dist, i});
        sort(begin(psym), end(psym));
        if (int(psym.size()) == 4) psym.pop_back();
      }
    }
  }
  int rec = 1e9, cand;
  for (int i = (0); i < (min(3, int(pnum.size()))); ++i) {
    for (int j = (0); j < (min(3, int(palp.size()))); ++j) {
      for (int z = (0); z < (min(3, int(psym.size()))); ++z) {
        if (pnum[i].second == palp[j].second ||
            pnum[i].second == psym[z].second ||
            palp[j].second == psym[z].second)
          continue;
        cand = pnum[i].first + palp[j].first + psym[z].first;
        rec = min(rec, cand);
      }
    }
  }
  cout << rec << endl;
  return 0;
}
