#include <bits/stdc++.h>
using namespace std;
int cost[55][3];
char str[55];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%s", str);
    for (int j = 0; j < 3; j++) cost[i][j] = 1000;
    for (int j = 0; j < M; j++) {
      if ('a' <= str[j] && str[j] <= 'z')
        cost[i][0] = min(cost[i][0], min(j, M - j));
      if ('0' <= str[j] && str[j] <= '9')
        cost[i][1] = min(cost[i][1], min(j, M - j));
      if (str[j] == '#' || str[j] == '*' || str[j] == '&')
        cost[i][2] = min(cost[i][2], min(j, M - j));
    }
  }
  int ans = 10000;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) {
        if (i == j || j == k || i == k) continue;
        ans = min(ans, cost[i][0] + cost[j][1] + cost[k][2]);
      }
  printf("%d\n", ans);
  return 0;
}
