#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int oo = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
char s[100][100];
int n, m;
int check(int ii, int jj, int kk) {
  int res = 0;
  int flag = 0;
  int a, b, c;
  for (int i = 1; i <= m; i++) {
    if (isdigit(s[ii][i])) {
      a = i - 1;
      flag++;
      break;
    }
  }
  for (int i = m, j = 1; i >= 1; i--, j++) {
    if (isdigit(s[ii][i])) {
      a = min(a, j);
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (isalpha(s[jj][i])) {
      b = i - 1;
      flag++;
      break;
    }
  }
  for (int i = m, j = 1; i >= 1; i--, j++) {
    if (isalpha(s[jj][i])) {
      b = min(b, j);
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!isalpha(s[kk][i]) && !isdigit(s[kk][i])) {
      c = i - 1;
      flag++;
      break;
    }
  }
  for (int i = m, j = 1; i >= 1; i--, j++) {
    if (!isalpha(s[kk][i]) && !isdigit(s[kk][i])) {
      c = min(c, j);
      break;
    }
  }
  if (flag != 3) return oo;
  return a + b + c;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  int ans = oo;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      for (int k = j + 1; k <= n; k++) {
        ans = min(check(i, j, k), ans);
        ans = min(check(i, k, j), ans);
        ans = min(check(j, i, k), ans);
        ans = min(check(j, k, i), ans);
        ans = min(check(k, i, j), ans);
        ans = min(check(k, j, i), ans);
      }
  cout << ans << endl;
}
