#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, m, ans = 1e9;
int f[N][4];
char s[N][N];
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = 10 * x + c - '0';
    c = getchar();
  }
  x *= f;
}
const int inf = 0x3f3f3f3f;
int main() {
  read(n);
  read(m);
  for (int i = 0; i <= n - 1; i++) scanf("%s", s[i]);
  for (int i = 0; i <= n - 1; i++)
    for (int j = 1; j <= 3; j++) f[i][j] = 100000;
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++)
      if (s[i][j] >= '0' && s[i][j] <= '9')
        f[i][1] = ((f[i][1]) < (((j) < (m - j) ? (j) : (m - j)))
                       ? (f[i][1])
                       : (((j) < (m - j) ? (j) : (m - j))));
      else if (s[i][j] >= 'a' && s[i][j] <= 'z')
        f[i][2] = ((f[i][2]) < (((j) < (m - j) ? (j) : (m - j)))
                       ? (f[i][2])
                       : (((j) < (m - j) ? (j) : (m - j))));
      else if (s[i][j] == '#' || s[i][j] == '*' || s[i][j] == '&')
        f[i][3] = ((f[i][3]) < (((j) < (m - j) ? (j) : (m - j)))
                       ? (f[i][3])
                       : (((j) < (m - j) ? (j) : (m - j))));
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= n - 1; j++)
      for (int k = 0; k <= n - 1; k++)
        if (i != j && i != k && j != k) {
          ans = ((f[i][1] + f[j][2] + f[k][3]) < (ans)
                     ? (f[i][1] + f[j][2] + f[k][3])
                     : (ans));
        }
  cout << ans;
  return 0;
}
