#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[51];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<pair<int, int> > q1, q2, q3;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] >= '0' && s[i][j] <= '9') {
        q1.push_back(make_pair(min(j, m - j), i));
      } else if (s[i][j] >= 'a' && s[i][j] <= 'z') {
        q2.push_back(make_pair(min(j, m - j), i));
      } else if (s[i][j] == '#' || s[i][j] == '*' || s[i][j] == '.') {
        q3.push_back(make_pair(min(j, m - j), i));
      }
    }
  }
  int mn = 1000000;
  int a, b, c;
  sort(q1.begin(), q1.end());
  sort(q2.begin(), q2.end());
  sort(q3.begin(), q3.end());
  for (int i = 0; i < q1.size(); i++) {
    for (int j = 0; j < q2.size(); j++) {
      for (int k = 0; k < q3.size(); k++) {
        if (q1[i].second != q2[j].second && q1[i].second != q3[k].second &&
            q3[k].second != q2[j].second) {
          mn = min(mn, q1[i].first + q2[j].first + q3[k].first);
        }
      }
    }
  }
  if (mn == 1000000)
    cout << 0 << endl;
  else
    cout << mn << endl;
  return 0;
}
