#include <bits/stdc++.h>
using namespace std;
int aa[55];
vector<pair<int, int> > xa;
vector<pair<int, int> > ya;
vector<pair<int, int> > za;
vector<pair<int, int> >::iterator it;
int ba[55];
char arr[55][55];
int ca[55];
int main() {
  ios::sync_with_stdio(0);
  int n, m, i, j, k, a, b, c, ans;
  ans = 0;
  string s;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> s;
    for (j = 0; j < m; j++) {
      arr[i][j] = s[j];
    }
  }
  bool f, g, h;
  for (i = 0; i < n; i++) {
    a = b = c = 199;
    aa[i] = ba[i] = ca[i] = 10000;
    f = g = h = 0;
    for (j = 0; j < m; j++) {
      if (arr[i][j] >= 48 && arr[i][j] <= 57) {
        f = 1;
        aa[i] = min(aa[i], min(j, abs(m - j)));
      }
    }
    if (f == 0) aa[i] = 10070;
    xa.push_back(make_pair(aa[i], i));
    for (j = 0; j < m; j++) {
      if (arr[i][j] >= 97 && arr[i][j] <= 122) {
        g = 1;
        ba[i] = min(ba[i], min(j, abs(m - j)));
      }
    }
    if (g == 0) ba[i] = 1000;
    ya.push_back(make_pair(ba[i], i));
    for (j = 0; j < m; j++) {
      if (arr[i][j] == '&' || arr[i][j] == '*' || arr[i][j] == '#') {
        h = 1;
        ca[i] = min(ca[i], min(j, abs(m - j)));
      }
    }
    if (h == 0) ca[i] = 1000;
    za.push_back(make_pair(ca[i], i));
  }
  sort(xa.begin(), xa.end());
  sort(ya.begin(), ya.end());
  sort(za.begin(), za.end());
  it = xa.begin();
  ans = (*it).first;
  a = (*it).second;
  it = ya.begin();
  while ((*it).second == a) {
    it++;
  }
  ans += (*it).first;
  b = (*it).second;
  it = za.begin();
  while ((*it).second == a || (*it).second == b) {
    it++;
  }
  ans += (*it).first;
  cout << ans << endl;
  return 0;
}
