#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) cin >> s[i];
  int res = 1 << 30;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int a = 0, b = 0, c = 0;
      for (int k = 0; k < n; ++k) {
        if (k != i && k != j) {
          if ('0' <= s[k][0] && s[k][0] <= '9') a = 1;
          if ('a' <= s[k][0] && s[k][0] <= 'z') b = 1;
          if ('*' == s[k][0] || s[k][0] == '#' || s[k][0] == '&') c = 1;
        }
      }
      for (int k = 0; k < m; ++k) {
        for (int l = 0; l < m; ++l) {
          int aa = 0, bb = 0, cc = 0;
          if (k != i && k != j) {
            if ('0' <= s[i][k] && s[i][k] <= '9') aa = 1;
            if ('a' <= s[i][k] && s[i][k] <= 'z') bb = 1;
            if ('*' == s[i][k] || s[i][k] == '#' || s[i][k] == '&') cc = 1;
            if ('0' <= s[j][l] && s[j][l] <= '9') aa = 1;
            if ('a' <= s[j][l] && s[j][l] <= 'z') bb = 1;
            if ('*' == s[j][l] || s[j][l] == '#' || s[j][l] == '&') cc = 1;
            if (max(a, aa) + max(b, bb) + max(c, cc) == 3) {
              res = min(res, min(k, m - k) + min(l, m - l));
            }
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
