#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m;
char ch[100][100];
int visit[100][3];
int main() {
  while (~scanf("%d %d", &n, &m)) {
    memset(visit, INF, sizeof visit);
    for (int i = 1; i <= n; i++) {
      scanf("%s", ch[i] + 1);
      for (int j = 1; j <= m; j++) {
        if (ch[i][j] >= '0' && ch[i][j] <= '9')
          visit[i][0] = min(visit[i][0], min(j, m + 2 - j));
        else if (ch[i][j] >= 'a' && ch[i][j] <= 'z')
          visit[i][1] = min(visit[i][1], min(j, m + 2 - j));
        else
          visit[i][2] = min(visit[i][2], min(j, m + 2 - j));
      }
    }
    int ans = INF;
    for (int i = 1; i <= n; i++) {
      if (visit[i][0] == INF) continue;
      for (int j = 1; j <= n; j++) {
        if (i == j || visit[j][1] == INF) continue;
        for (int k = 1; k <= n; k++) {
          if (i == k || j == k || visit[k][2] == INF) continue;
          ans = min(ans, visit[i][0] + visit[j][1] + visit[k][2] - 3);
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
