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