#include <bits/stdc++.h>
using namespace std;
long long int fast(long long int n, long long int a, long long int m) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return a;
  else {
    long long int r = fast(n / 2, a, m);
    if (n % 2 == 0) {
      return (((r % m) * (r % m)) % m);
    } else {
      return (((((r % m) * a) % m) * r) % m);
    }
  }
}
long long int sear(long long int X, long long int lo, long long int hi) {
  long long int mid;
  long long int ind = -1e15;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (mid > X) {
      ind = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return ind;
}
int d[100], c[100], p[100], ans = 1e6;
int main() {
  int n, m;
  string s;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    d[i] = 10000;
    c[i] = 10000;
    p[i] = 10000;
    for (int j = 0; j < m; j++) {
      if (s[j] >= '0' && s[j] <= '9') d[i] = min(d[i], min(j, m - j));
      if (s[j] >= 'a' && s[j] <= 'z') c[i] = min(c[i], min(j, m - j));
      if (s[j] == '#' || s[j] == '*' || s[j] == '&') {
        p[i] = min(p[i], min(j, m - j));
      }
    }
  }
  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 || k == i) continue;
        ans = min(ans, d[i] + c[j] + p[k]);
      }
  cout << ans << endl;
}
