#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> v;
vector<int> sol[3];
int main(int argc, const char* argv[]) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sol[0].resize(n);
  sol[1].resize(n);
  sol[2].resize(n);
  for (int i = 0; i < n; i++) {
    int closest_digit = m + 1, closest_letter = m + 1, closest_symbol = m + 1;
    for (int j = 0; j <= m / 2; j++) {
      if (isdigit(v[i][j])) {
        closest_digit = min(closest_digit, j);
      } else if (islower(v[i][j])) {
        closest_letter = min(closest_letter, j);
      } else if (strchr("*#&", v[i][j]) != NULL) {
        closest_symbol = min(closest_symbol, j);
      }
    }
    for (int j = m - 1; j >= m / 2; j--) {
      if (isdigit(v[i][j])) {
        closest_digit = min(closest_digit, m - j);
      } else if (islower(v[i][j])) {
        closest_letter = min(closest_letter, m - j);
      } else if (strchr("*#&", v[i][j]) != NULL) {
        closest_symbol = min(closest_symbol, m - j);
      }
    }
    sol[0][i] = closest_digit;
    sol[1][i] = closest_letter;
    sol[2][i] = closest_symbol;
  }
  int ans = 3 * 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 && i != k) {
          int q = sol[0][i] + sol[1][j] + sol[2][k];
          ans = min(ans, q);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
