#include <bits/stdc++.h>
using namespace std;
const long long over999 = 12345678;
const double eps = 1e-9;
const double Pi = acos(-1);
const long long md = 1e9 + 7;
bool checkDig(char c) { return (c >= '0' && c <= '9'); }
bool checkSym(char c) { return (c >= 'a' && c <= 'z'); }
bool checkAbr(char c) { return (c == '&' || c == '*' || c == '#'); }
bool check(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  if (a.second != b.second && b.second != c.second && a.second != c.second)
    return true;
  return false;
}
vector<pair<int, int>> vdig, vsym, vabr;
int n, m;
string s[100];
int mdig, msym, mabr;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    mdig = over999;
    msym = over999;
    mabr = over999;
    for (int j = 0; j < s[i].length(); j++) {
      if (checkDig(s[i][j]))
        mdig = min(mdig, min(j, m - j));
      else if (checkSym(s[i][j]))
        msym = min(msym, min(j, m - j));
      else if (checkAbr(s[i][j]))
        mabr = min(mabr, min(j, m - j));
    }
    vdig.push_back({mdig, i});
    vsym.push_back({msym, i});
    vabr.push_back({mabr, i});
  }
  sort(vdig.begin(), vdig.end());
  sort(vsym.begin(), vsym.end());
  sort(vabr.begin(), vabr.end());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (check(vdig[i], vsym[j], vabr[k])) {
          return cout << vdig[i].first + vsym[j].first + vabr[k].first, 0;
        }
      }
    }
  }
  return 0;
}
