#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int INF = 1e8 + 7;
char s[maxn];
int vis[maxn][3];
int check(char j) {
  if (j >= '0' && j <= '9')
    return 0;
  else if (j >= 'a' && j <= 'z')
    return 1;
  else if (j == '*' || j == '#' || j == '&')
    return 2;
  return INF;
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(vis, INF, sizeof(vis));
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      vis[i][0] = vis[i][1] = vis[i][2] = INF;
      for (int j = 0; j < m; j++) {
        int u = check(s[j]);
        int t = min(j, m - j);
        vis[i][u] = min(vis[i][u], t);
      }
    }
    int ans = INF;
    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)
            ans = min(ans, vis[i][0] + vis[j][1] + vis[k][2]);
        }
    printf("%d\n", ans);
  }
  return 0;
}
