#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
string s[55];
int d[55][3];
int n, m;
void R(string &s, int *d) {
  cin >> s;
  d[0] = d[1] = d[2] = 1e8;
  for (int i = 0; i < int(m); ++i) {
    char c = s[i];
    int type = 2;
    if (isdigit(c)) {
      type = 0;
    } else if (isalpha(c)) {
      type = 1;
    }
    d[type] = min(d[type], min(i, m - i));
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < int(n); ++i) {
    R(s[i], d[i]);
  }
  int ans = INT_MAX;
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j)
      for (int k = 0; k < int(n); ++k) {
        if (i == j || j == k || i == k) continue;
        ans = min(ans, d[i][0] + d[j][1] + d[k][2]);
      }
  printf("%d\n", ans);
  return 0;
}
