#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
bool is_cif(char c) { return (c >= '0' && c <= '9'); }
bool is_simv(char c) { return (c == '#' || c == '*' || c == '&'); }
bool is_buk(char c) { return (c >= 'a' && c <= 'z'); }
int main() {
  int n, m;
  long long ans = INF;
  cin >> n >> m;
  vector<string> mass(n);
  for (auto &el : mass) cin >> el;
  vector<long long> cif(n, INF), buk(n, INF), simv(n, INF);
  for (int i = 0; i < n; i++) {
    string now = mass[i];
    long long l = 0;
    while (l < m && !is_cif(now[l])) l++;
    if (l < m && is_cif(now[l])) cif[i] = min(cif[i], l);
    l = 0;
    while (l < m && !is_cif(now[m - l - 1])) l++;
    if (l < m && is_cif(now[m - l - 1])) cif[i] = min(cif[i], l + 1);
  }
  for (int i = 0; i < n; i++) {
    string now = mass[i];
    long long l = 0;
    while (l < m && !is_buk(now[l])) l++;
    if (l < m && is_buk(now[l])) buk[i] = min(buk[i], l);
    l = 0;
    while (l < m && !is_buk(now[m - l - 1])) l++;
    if (l < m && is_buk(now[m - l - 1])) buk[i] = min(buk[i], l + 1);
  }
  for (int i = 0; i < n; i++) {
    string now = mass[i];
    long long l = 0;
    while (l < m && !is_simv(now[l])) l++;
    if (l < m && is_simv(now[l])) simv[i] = min(simv[i], l);
    l = 0;
    while (l < m && !is_simv(now[m - l - 1])) l++;
    if (l < m && is_simv(now[m - l - 1])) simv[i] = min(simv[i], l + 1);
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++) {
        ans = min(ans, cif[i] + buk[j] + simv[k]);
        ans = min(ans, cif[i] + buk[k] + simv[j]);
        ans = min(ans, cif[j] + buk[k] + simv[i]);
        ans = min(ans, cif[j] + buk[i] + simv[k]);
        ans = min(ans, cif[k] + buk[i] + simv[j]);
        ans = min(ans, cif[k] + buk[j] + simv[i]);
      }
  cout << ans;
  return 0;
}
