#include <bits/stdc++.h>
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;
;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
bool cmpbig(int a, int b) { return a > b; }
bool cmpsmall(int a, int b) { return a < b; }
using namespace std;
int cnt, n;
int vis_line[110];
int vis[110][3];
void dfs(int j, int pos) {
  if (j >= 3) {
    cnt = min(cnt, pos);
    return;
  }
  if (pos >= cnt) return;
  for (int i = 0; i < n; i++) {
    if (!vis_line[i]) {
      vis_line[i] = 1;
      dfs(j + 1, pos + vis[i][j]);
      vis_line[i] = 0;
    }
  }
}
int main() {
  int m;
  while (~scanf("%d%d", &n, &m)) {
    char str[110][110];
    int i, j;
    memset(vis, 9999, sizeof(vis));
    memset(vis_line, 0, sizeof(vis_line));
    for (i = 0; i < n; i++) {
      scanf("%s", str[i]);
      for (j = 0; j < m; j++) {
        if (str[i][j] >= 'a' && str[i][j] <= 'z')
          vis[i][0] = min(vis[i][0], min(j, m - j));
        else if (str[i][j] <= '9' && str[i][j] >= '0')
          vis[i][1] = min(vis[i][1], min(j, m - j));
        else
          vis[i][2] = min(vis[i][2], min(j, m - j));
      }
    }
    cnt = INF;
    dfs(0, 0);
    printf("%d\n", cnt);
  }
  return 0;
}
