#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T Set(T N, T pos) {
  return N = N | (1 << pos);
}
template <class T>
inline T reset(T N, T pos) {
  return N = N & ~(1 << pos);
}
template <class T>
inline bool check(T N, T pos) {
  return (bool)(N & (1 << pos));
}
const int inf = 1e7;
int ara[51][3] = {0};
string s[51];
int dp[51][8], n, m;
int func(int i, int b) {
  if (b == 7) return 0;
  if (i == n) return inf;
  if (dp[i][b] != -1) return dp[i][b];
  int p, q, r;
  p = q = r = inf;
  if (check(b, 0) == 0 && ara[i][0] != inf)
    p = min(ara[i][0] + func(i + 1, Set(b, 0)), func(i + 1, b));
  else
    p = func(i + 1, b);
  if (check(b, 1) == 0 && ara[i][1] != inf)
    q = min(ara[i][1] + func(i + 1, Set(b, 1)), func(i + 1, b));
  else
    q = func(i + 1, b);
  if (check(b, 2) == 0 && ara[i][2] != inf)
    r = min(ara[i][2] + func(i + 1, Set(b, 2)), func(i + 1, b));
  else
    r = func(i + 1, b);
  return dp[i][b] = min(p, min(q, r));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 3; j++) ara[i][j] = inf;
  }
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] >= 'a' && s[i][j] <= 'z')
        ara[i][0] = min(ara[i][0], min(j, m - j));
      else if (s[i][j] >= '0' && s[i][j] <= '9')
        ara[i][1] = min(ara[i][1], min(j, m - j));
      else
        ara[i][2] = min(ara[i][2], min(j, m - j));
    }
  }
  memset(dp, -1, sizeof(dp));
  int res = func(0, 0);
  cout << res << endl;
  return 0;
}
