#include <bits/stdc++.h>
using namespace std;
int judge(string s);
int main() {
  int n, m;
  cin >> n >> m;
  string *s = new string[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  int res = 10000;
  int *l_store = new int[50];
  int *n_store = new int[50];
  int *s_store = new int[50];
  for (int i = 0; i < 50; i++) l_store[i] = n_store[i] = s_store[i] = 10000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0 && 'a' <= s[i].at(j) && s[i].at(j) <= 'z') {
        l_store[i] = 0;
        break;
      }
      if (j != 0 && (('a' <= s[i].at(j) && s[i].at(j) <= 'z') ||
                     ('a' <= s[i].at(m - j) && s[i].at(m - j) <= 'z'))) {
        l_store[i] = j;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0 && '0' <= s[i].at(j) && s[i].at(j) <= '9') {
        n_store[i] = 0;
        break;
      }
      if (j != 0 && (('0' <= s[i].at(j) && s[i].at(j) <= '9') ||
                     ('0' <= s[i].at(m - j) && s[i].at(m - j) <= '9'))) {
        n_store[i] = j;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0 &&
          ('*' == s[i].at(j) || s[i].at(j) == '#' || s[i].at(j) == '&')) {
        s_store[i] = 0;
        break;
      }
      if (j != 0 && ('*' == s[i].at(j) || s[i].at(j) == '#' ||
                     s[i].at(j) == '&' || '*' == s[i].at(m - j) ||
                     s[i].at(m - j) == '#' || s[i].at(m - j) == '&')) {
        s_store[i] = j;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (i == j || i == k || k == j) continue;
        res = min(res, s_store[i] + l_store[j] + n_store[k]);
      }
    }
  }
  cout << res;
}
