#include <bits/stdc++.h>
using namespace std;
struct sym {
  int Let, Num, S;
};
sym B[52];
int n, m;
string A[52];
void func(int x, string s) {
  B[x].Let = 100;
  B[x].Num = 100;
  B[x].S = 100;
  for (int i = 0; i < m; i++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      B[x].Let = min(B[x].Let, min(i, m - i));
    else if (s[i] == '#' || s[i] == '*' || s[i] == '&')
      B[x].S = min(B[x].S, min(i, m - i));
    else
      B[x].Num = min(B[x].Num, min(i, m - i));
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    func(i, A[i]);
  }
  int res = 100;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      for (int k = 1; k <= n; k++) {
        if (k == j || k == i) continue;
        res = min(res, B[i].Num + B[j].Let + B[k].S);
      }
    }
  }
  cout << res << endl;
  return 0;
}
