#include <bits/stdc++.h>
using namespace std;
int start[50 + 10][5];
int main() {
  int n, m, ans = 10000;
  string a;
  cin >> n >> m;
  for (int i = 0; i < 50 + 10; i++) {
    for (int k = 0; k < 5; k++) {
      start[i][k] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a.find_first_of("1234567890") != string::npos) {
      start[i][0] =
          min(a.find_first_of("1234567890"), m - a.find_last_of("1234567890"));
    }
    if (a.find_first_of("qwertyuiopasdfghjklzxcvbnm") != string::npos) {
      start[i][1] = min(a.find_first_of("qwertyuiopasdfghjklzxcvbnm"),
                        m - a.find_last_of("qwertyuiopasdfghjklzxcvbnm"));
    }
    if (a.find_first_of("*&#") != string::npos) {
      start[i][2] = min(a.find_first_of("*&#"), m - a.find_last_of("*&#"));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      for (int j = 0; j < n; j++) {
        if (start[i][0] == -1 || start[k][1] == -1 || start[j][2] == -1 ||
            i == j || k == i || k == j) {
          continue;
        }
        ans = min(ans, start[i][0] + start[k][1] + start[j][2]);
      }
    }
  }
  cout << ans;
}
