#include <bits/stdc++.h>
using namespace std;
int getShortestTo(const string& s, bool digit, bool lowercase, bool symbol) {
  int minimumDist = INT_MAX, n = s.size();
  for (int i = 0; i < n; ++i) {
    if (digit) {
      if (s[i] >= '0' && s[i] <= '9') {
        minimumDist = min(minimumDist, min(i, (n - i)));
      }
    } else if (lowercase) {
      if (s[i] >= 'a' && s[i] <= 'z') {
        minimumDist = min(minimumDist, min(i, (n - i)));
      }
    } else if (symbol) {
      if (s[i] == '&' || s[i] == '*' || s[i] == '#') {
        minimumDist = min(minimumDist, min(i, (n - i)));
      }
    }
  }
  return (minimumDist < INT_MAX ? minimumDist : -1);
}
int main() {
  int m, n;
  cin >> n >> m;
  string s[50];
  int p[50];
  int shortestToLowercase[50];
  int shortestToDigit[50];
  int shortestToSymbol[50];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    shortestToLowercase[i] = -1;
    shortestToDigit[i] = -1;
    shortestToSymbol[i] = -1;
  }
  for (int i = 0; i < n; ++i) {
    shortestToLowercase[i] = getShortestTo(s[i], false, true, false);
    shortestToDigit[i] = getShortestTo(s[i], true, false, false);
    shortestToSymbol[i] = getShortestTo(s[i], false, false, true);
  }
  int result = INT_MAX;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i != j) {
        for (int k = 0; k < n; ++k) {
          if (i != k && j != k && shortestToLowercase[i] >= 0 &&
              shortestToDigit[j] >= 0 && shortestToSymbol[k] >= 0) {
            int tmp = shortestToLowercase[i] + shortestToDigit[j] +
                      shortestToSymbol[k];
            if (tmp < result) {
              result = tmp;
            }
          }
        }
      }
    }
  }
  cout << result << endl;
  return 0;
}
