#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int inf = 0x3f3f3f3f;
int n, m;
int w[MAXN][10];
char s[MAXN];
int ans;
bool vis[MAXN];
void dfs(int j, int sum) {
  if (j == 3) {
    ans = min(ans, sum);
    return;
  }
  if (sum > ans) return;
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      vis[i] = 1;
      dfs(j + 1, sum + w[i][j]);
      vis[i] = 0;
    }
  }
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  memset(w, inf, sizeof(w));
  for (i = 0; i < n; ++i) {
    scanf("%s", s);
    for (j = 0; j < m; ++j) {
      if (isdigit(s[j]))
        w[i][0] = min(w[i][0], min(j, m - j));
      else if (islower(s[j]))
        w[i][1] = min(w[i][1], min(j, m - j));
      else
        w[i][2] = min(w[i][2], min(j, m - j));
    }
  }
  ans = inf;
  dfs(0, 0);
  printf("%d\n", ans);
  return 0;
}
