#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
template <class... T>
void printl(T&&...) {}
template <class... T>
void printc(T&&...) {}
template <class... T>
void prints(T&&...) {}
template <class... T>
void printd(T&&...) {}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ps(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      ps[i][j] = ('0' <= c && c <= '9'               ? 0
                  : c == '#' || c == '*' || c == '&' ? 2
                                                     : 1);
    }
  }
  prints(ps);
  int ans = M;
  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;
        }
        int cand = 0;
        bool ok = false;
        for (int l = 0; l < m; l++) {
          if (ps[i][l] == 0 || l && ps[i][m - l] == 0) {
            cand = l;
            ok = true;
            break;
          }
        }
        if (!ok) {
          continue;
        }
        ok = false;
        for (int l = 0; l < m; l++) {
          if (ps[j][l] == 1 || l && ps[j][m - l] == 1) {
            cand += l;
            ok = true;
            break;
          }
        }
        if (!ok) {
          continue;
        }
        ok = false;
        for (int l = 0; l < m; l++) {
          if (ps[k][l] == 2 || l && ps[k][m - l] == 2) {
            cand += l;
            ok = true;
            break;
          }
        }
        if (!ok) {
          continue;
        }
        prints(i, j, k, cand);
        ans = min(ans, cand);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
