#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = 10000;
const double EPS = 1e-9;
const double pi = acos(-1);
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
int n, m;
int compute_alpha(string s) {
  int res = INF;
  for (__typeof(0) i = (0); i < (m); ++i) {
    if (islower(s[i])) {
      res = min(res, min(i, m - i));
    }
  }
  return res;
}
int compute_digit(string s) {
  int res = INF;
  for (__typeof(0) i = (0); i < (m); ++i) {
    if (isdigit(s[i])) {
      res = min(res, min(i, m - i));
    }
  }
  return res;
}
int compute_special(string s) {
  int res = INF;
  for (__typeof(0) i = (0); i < (m); ++i) {
    if (s[i] == '#' || s[i] == '*' || s[i] == '&') {
      res = min(res, min(i, m - i));
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  vector<string> p(n);
  for (__typeof(0) i = (0); i < (n); ++i) {
    cin >> p[i];
  }
  int res = INF;
  for (__typeof(0) digit = (0); digit < (n); ++digit) {
    for (__typeof(0) alpha = (0); alpha < (n); ++alpha) {
      if (digit == alpha) continue;
      for (__typeof(0) spec = (0); spec < (n); ++spec) {
        if (spec == digit || spec == alpha) continue;
        res = min(res, compute_digit(p[digit]) + compute_alpha(p[alpha]) +
                           compute_special(p[spec]));
      }
    }
  }
  printf("%d\n", res);
}
