#include <bits/stdc++.h>
using namespace std;
string s[51];
long long dp[51][10];
long long n, m;
string heroooo3 = "#*&";
long long dpfun(int ind, int mask) {
  if (ind >= n) return ((mask == 7) ? 0 : 1e9);
  if (dp[ind][mask] != -1) return dp[ind][mask];
  long long bbdalebas = 1e10, he;
  int newmask = mask;
  for (int i = 0; i < m; i++) {
    he = min((long long)i, m - i);
    if (isalpha(s[ind][i]))
      newmask = mask | 1;
    else if (isdigit(s[ind][i]))
      newmask = mask | 2;
    else if (heroooo3.find(s[ind][i]) != -1)
      newmask = mask | 4;
    bbdalebas = min(bbdalebas, he + dpfun(ind + 1, newmask));
  }
  return dp[ind][mask] = bbdalebas;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> n >> m) {
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; i++) cin >> s[i];
    int ed = dpfun(0, 0);
    cout << ed << '\n';
  }
  return 0;
}
