#include <bits/stdc++.h>
using namespace std;
template <typename T>
T input() {
  T ans = 0, m = 1;
  char c = ' ';
  while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
  if (c == '-') m = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + (c - '0'), c = getchar();
  }
  return ans * m;
}
string nextString(bool flag = false) {
  char ch;
  string ans = "";
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (1) {
    ans += ch;
    ch = getchar();
    if (!flag) {
      if (ch <= ' ') break;
    } else {
      if (ch < ' ') break;
    }
  }
  return ans;
}
char nextChar() {
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  return ch;
}
void read(string& s) { s = nextString(); }
void read(char& c) { c = nextChar(); }
template <typename T>
void read(T& a) {
  a = input<T>();
}
template <typename T, typename... R>
void read(T& a, R&... r) {
  read(a);
  read(r...);
}
int main() {
  int n, m;
  read(n, m);
  vector<long long> d1(n), d2(n), d3(n);
  for (int i = 0; i < n; ++i) {
    string y;
    read(y);
    int a = INT_MAX, b = INT_MAX, c = INT_MAX;
    for (int j = 0; j < m; ++j) {
      if (y[j] >= 'a' && y[j] <= 'z') a = min(a, min(j, m - j));
      if (y[j] >= '0' && y[j] <= '9') b = min(b, min(j, m - j));
      if (y[j] == '#' || y[j] == '*' || y[j] == '&') c = min(c, min(j, m - j));
    }
    d1[i] = a, d2[i] = b, d3[i] = c;
  }
  long long ans = INT_MAX;
  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) ans = min(ans, (d1[i] + d2[j] + d3[k]));
  cout << ans;
}
