#include <bits/stdc++.h>
using namespace std;
char s[55][55];
int q[300] = {0};
int dis[55][4];
int main() {
  int n, m;
  for (int i = 0; i < 26; i++) q['a' + i] = 1;
  for (int i = 0; i < 10; i++) q['0' + i] = 2;
  q['*'] = q['&'] = q['#'] = 3;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 1; j < 4; j++) dis[i][j] = 55;
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; j++)
      dis[i][q[s[i][j]]] = min(dis[i][q[s[i][j]]], min(j, m - j));
  }
  int ans = 200;
  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, dis[i][1] + dis[j][2] + dis[k][3]);
  printf("%d\n", ans);
}
