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