#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, m, DP[55][2][2][2];
string str[55];
int dp(int i, bool dig, bool alpha, bool special) {
  if (i == n) {
    if (dig && alpha && special) return 0;
    return (1000000007LL);
  }
  int &ans = DP[i][dig][alpha][special];
  if (ans != -1) return ans;
  ans = (1000000007LL);
  for (int j = 0; j < m; j++) {
    int cost = min(j, m - j);
    if (isdigit(str[i][j])) {
      ans = min(ans, cost + dp(i + 1, true, alpha, special));
    } else if (isalpha(str[i][j])) {
      ans = min(ans, cost + dp(i + 1, dig, true, special));
    } else {
      ans = min(ans, cost + dp(i + 1, dig, alpha, true));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  memset(DP, -1, sizeof(DP));
  cout << dp(0, 0, 0, 0);
  return 0;
}
