#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 51;
int n, m;
char tab[N][N];
long long int dist[N][3];
long long int dp[N][2][2][2];
int menordist(int lin, int x) {
  if (x == 0) {
    int cu = INF;
    for (int i = 0; i < m; i++) {
      if (tab[lin][i] >= '0' and tab[lin][i] <= '9')
        cu = min(min(cu, i), m - i);
    }
    return cu;
  } else if (x == 1) {
    int cu = INF;
    for (int i = 0; i < m; i++) {
      if (tab[lin][i] >= 'a' and tab[lin][i] <= 'z')
        cu = min(min(cu, i), m - i);
    }
    return cu;
  } else {
    int cu = INF;
    for (int i = 0; i < m; i++) {
      if (tab[lin][i] == '#' or tab[lin][i] == '*' or tab[lin][i] == '&')
        cu = min(min(cu, i), m - i);
    }
    return cu;
  }
  return 0;
}
long long int solve(int i, int dig, int letra, int carac) {
  if (i == 0) {
    if (dig and letra and carac) return 0;
    int r = dig + letra + carac;
    if (r < 2) return INF;
    if (!dig) return dist[i][0];
    if (!letra) return dist[i][1];
    return dist[i][2];
  }
  long long int ret = INF;
  if (dp[i][dig][letra][carac] != -1) return dp[i][dig][letra][carac];
  for (int j = 0; j < 3; j++) {
    if (dist[i][j] == INF) continue;
    if (j == 0) ret = min(ret, solve(i - 1, 1, letra, carac) + dist[i][j]);
    if (j == 1) ret = min(ret, solve(i - 1, dig, 1, carac) + dist[i][j]);
    if (j == 2) ret = min(ret, solve(i - 1, dig, letra, 1) + dist[i][j]);
  }
  ret = min(solve(i - 1, dig, letra, carac), ret);
  return dp[i][dig][letra][carac] = ret;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> tab[i][j];
    }
  }
  memset(dist, INF, sizeof(dist));
  for (int i = 0; i < n; i++) {
    dist[i][0] = menordist(i, 0);
    dist[i][1] = menordist(i, 1);
    dist[i][2] = menordist(i, 2);
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(n - 1, 0, 0, 0) << endl;
  return 0;
}
