#include <bits/stdc++.h>
using namespace std;
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1001;
int dp[N][3];
string str[55];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) dp[i][j] = 1000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (isalpha(str[i][j])) dp[i][0] = min(dp[i][0], min(j, m - j));
      if (str[i][j] >= '0' && str[i][j] <= '9')
        dp[i][1] = min(dp[i][1], min(j, m - j));
      if (str[i][j] == '#' || str[i][j] == '&' || str[i][j] == '*')
        dp[i][2] = min(dp[i][2], min(j, m - j));
    }
  }
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int k = 0; k < n; k++) {
        if (i == k || j == k) continue;
        ans = min(ans, dp[i][0] + dp[j][1] + dp[k][2]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
