#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m;
string a[55];
int dp[55][2][2][2];
int calc(int ind, int digit, int letter, int symbol) {
  if (ind == n) {
    if (digit + letter + symbol < 3) return inf;
    return 0;
  }
  int &res = dp[ind][digit][letter][symbol];
  if (res != -1) return res;
  res = inf;
  for (int i = 0; i < m; i++) {
    char c = a[ind][i];
    int d = min(i, m - i);
    if (c >= '0' && c <= '9')
      res = min(res, d + calc(ind + 1, 1, letter, symbol));
    if (c == '#' || c == '*' || c == '&')
      res = min(res, d + calc(ind + 1, digit, letter, 1));
    if (c >= 'a' && c <= 'z')
      res = min(res, d + calc(ind + 1, digit, 1, symbol));
    res = min(res, d + calc(ind + 1, digit, letter, symbol));
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << calc(0, 0, 0, 0) << endl;
  return 0;
}
