#include <bits/stdc++.h>
using namespace std;
string s;
int a[60][4], ans;
int main() {
  int n, m;
  cin >> n >> m;
  memset(a, 1, sizeof(a));
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j <= m; j++) {
      if (isdigit(s[j])) a[i][1] = min(a[i][1], j);
      if (isalpha(s[j]) && s[j] >= 'a') a[i][2] = min(a[i][2], j);
      if (s[j] == '*' || s[j] == '#' || s[j] == '&') a[i][3] = min(a[i][3], j);
    }
    for (int j = m; j >= 0; j--) {
      if (isdigit(s[j])) a[i][1] = min(a[i][1], m - j);
      if (isalpha(s[j]) && s[j] >= 'a') a[i][2] = min(a[i][2], m - j);
      if (s[j] == '*' || s[j] == '#' || s[j] == '&')
        a[i][3] = min(a[i][3], m - j);
    }
  }
  int ans = 1 << 10;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      for (int k = 1; k <= n; k++) {
        if (i == k || k == j) continue;
        ans = min(ans, a[i][1] + a[j][2] + a[k][3]);
      }
    }
  }
  printf("%d\n", ans);
}
