#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cyfra;
  vector<int> znak;
  vector<int> litera;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    int c = -1;
    int z = -1;
    int l = -1;
    for (int k = 0; k < tmp.size(); k++) {
      if (tmp[k] >= 'a' && tmp[k] <= 'z' && l == -1)
        l = k;
      else if (tmp[k] >= '0' && tmp[k] <= '9' && c == -1)
        c = k;
      else if ((tmp[k] == '&' || tmp[k] == '#' || tmp[k] == '*') && z == -1)
        z = k;
    }
    int cnt = 1;
    for (int k = tmp.size() - 1; k >= 0; k--) {
      if (tmp[k] >= 'a' && tmp[k] <= 'z' && cnt < l)
        l = cnt;
      else if (tmp[k] >= '0' && tmp[k] <= '9' && cnt < c)
        c = cnt;
      else if ((tmp[k] == '&' || tmp[k] == '#' || tmp[k] == '*') && cnt < z)
        z = cnt;
      cnt++;
    }
    cyfra.push_back(c);
    litera.push_back(l);
    znak.push_back(z);
  }
  int tab[55];
  int suma = 0;
  int minis = 1000000000;
  for (int d = 0; d < 55; d++) tab[d] = 0;
  for (int i = 0; i < n; i++) {
    if (znak[i] != -1) {
      tab[i] = 1;
      suma += znak[i];
      for (int j = 0; j < n; j++) {
        if (tab[j] == 0 && cyfra[j] != -1) {
          suma += cyfra[j];
          tab[j] = 1;
          for (int k = 0; k < n; k++) {
            if (tab[k] == 0 && litera[k] != -1) {
              suma += litera[k];
              tab[k] = 1;
              if (suma < minis) minis = suma;
              tab[k] = 0;
              suma -= litera[k];
            }
          }
          tab[j] = 0;
          suma -= cyfra[j];
        }
      }
      tab[i] = 0;
      suma -= znak[i];
    }
  }
  cout << minis << endl;
  return 0;
}
