#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> pas(n);
  for (int i = 0; i < n; ++i) cin >> pas[i];
  vector<vector<long long> > req(3);
  for (int i = 0; i < n; ++i) {
    int k1 = INF, k2 = INF, k3 = INF;
    string s = pas[i];
    for (int j = 0; j < m; ++j) {
      if (s[j] <= '9' && s[j] >= '0' && k1 > j) k1 = j;
      if (s[j] <= 'z' && s[j] >= 'a' && k2 > j) k2 = j;
      if ((s[j] == '#' || s[j] == '*' || s[j] == '&') && (k3 > j)) k3 = j;
    }
    for (int j = m - 1; j >= 0; --j) {
      if (s[j] <= '9' && s[j] >= '0' && k1 > m - j) k1 = m - j;
      if (s[j] <= 'z' && s[j] >= 'a' && k2 > m - j) k2 = m - j;
      if ((s[j] == '#' || s[j] == '*' || s[j] == '&') && (k3 > m - j))
        k3 = m - j;
    }
    req[0].push_back(k1), req[1].push_back(k2), req[2].push_back(k3);
  }
  int ans = INF;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k)
        if (req[0][i] + req[1][j] + req[2][k] < ans && i != j && i != k) {
          ans = req[0][i] + req[1][j] + req[2][k];
        }
  cout << ans;
  return 0;
}
