#include <bits/stdc++.h>
using namespace std;
const int N = 555;
int a[N], b[N], c[N], n, m, ans = N * N * N;
char s[N][N];
int get(int a, int b) {
  return min(abs(a - b), min(abs(a + m - b), abs(b + m - a)));
}
int main() {
  cin >> n >> m;
  int i, j, k;
  for (i = 1; i <= n; i++) cin >> s[i] + 1;
  for (i = 1; i <= n; i++) {
    a[i] = b[i] = c[i] = N * N;
    for (j = 1; j <= m; j++) {
      if (s[i][j] >= '0' && s[i][j] <= '9') a[i] = min(a[i], get(1, j));
      if (s[i][j] >= 'a' && s[i][j] <= 'z') b[i] = min(b[i], get(1, j));
      if (s[i][j] == '#' || s[i][j] == '*' || s[i][j] == '&')
        c[i] = min(c[i], get(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, a[i] + b[j] + c[k]);
      }
  cout << ans;
  return 0;
}
