#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  int sp[51], digit[51], ch[51];
  for (int i = 0; i < 51; i++) {
    sp[i] = digit[i] = ch[i] = 1000000;
  }
  for (int i = 0; i < n; i++) {
    cin >> s;
    int curmin = 0, j, d;
    for (j = 0; j < m; j++) {
      if (isdigit(s[j])) {
        digit[i] = min(digit[i], min(j, m - j));
      } else if (s[j] == '&' || s[j] == '*' || s[j] == '#') {
        sp[i] = min(sp[i], min(j, m - j));
      } else {
        ch[i] = min(ch[i], min(j, m - j));
      }
    }
  }
  int X = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (i != j && j != k && i != k) X = min(X, digit[i] + sp[j] + ch[k]);
      }
    }
  }
  cout << X << "\n";
  return 0;
}
