#include <bits/stdc++.h>
using namespace std;
void Fastio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long fact[1000006], inv[1000006];
long long fp(long long base, long long exp) {
  if (exp == 0) return 1;
  long long ans = fp(base, exp / 2);
  ans = (ans * ans) % 998244353;
  if (exp % 2 != 0) ans = (ans * (base % 998244353)) % 998244353;
  return ans;
}
void calcFacAndInv(long long n) {
  fact[0] = inv[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]);
    inv[i] = fp(fact[i], 998244353 - 2);
  }
}
long long ncr(long long n, long long r) {
  return ((fact[n] * inv[r]) % 998244353 * inv[n - r]) % 998244353;
}
long long npr(long long n, long long r) {
  return (fact[n] * inv[n - r]) % 998244353;
}
long double NCR(int n, int m) {
  long double res = 1;
  m = min(m, n - m);
  for (int i = 0; i < m; i++) {
    res = res * (n - i) / (i + 1);
  }
  return res;
}
long long tol(string a) {
  long long res = 0;
  while (a[0] == '0') {
    a.erase(a.begin());
  }
  if (a == "") a = "0";
  for (int i = 0; i < a.size(); i++) {
    res *= 10;
    res += a[i] - '0';
  }
  return res;
}
int check(string a, string b) {
  for (int i = 0; i < a.size(); i++) {
    if (a[i] > b[i]) return 1;
    if (b[i] > a[i]) return -1;
  }
  return 0;
}
int main() {
  Fastio();
  long long n, m;
  cin >> n >> m;
  string arr[n];
  long long res = 1e19;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (long long i = 0; i < n; i++) {
    long long mn = 1e9;
    for (long long y = 0; y < m; y++) {
      if (arr[i][y] >= '0' && arr[i][y] <= '9') mn = min(mn, min(y, m - y));
    }
    for (long long y = 0; y < n; y++) {
      long long mn2 = 1e9;
      for (long long j = 0; j < m; j++) {
        if (arr[y][j] >= 'a' && arr[y][j] <= 'z') mn2 = min(mn2, min(j, m - j));
      }
      for (long long j = 0; j < n; j++) {
        if (i == y || i == j || y == j) continue;
        long long mn3 = 1e9;
        for (long long k = 0; k < m; k++) {
          if (arr[j][k] == '&' || arr[j][k] == '*' || arr[j][k] == '#')
            mn3 = min(mn3, min(k, m - k));
        }
        res = min(res, mn + mn2 + mn3);
      }
    }
  }
  cout << res << '\n';
  return 0;
}
