#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > a;
int minn(int b, int c, int d) { return min(b, min(c, d)); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> v(n + 1);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ans = 1e9;
  a.resize(n + 1);
  for (int i = 0; i < n; i++) {
    a[i].resize(4, 1e9);
    for (int j = 0; j < m; j++) {
      if (v[i][j] >= 'a' && v[i][j] <= 'z') {
        a[i][0] = minn(a[i][0], j, m - j);
      }
      if (v[i][j] >= '0' && v[i][j] <= '9') {
        a[i][1] = minn(a[i][1], j, m - j);
      }
      if (v[i][j] == '&') {
        a[i][2] = minn(a[i][2], j, m - j);
      }
      if (v[i][j] == '*') {
        a[i][2] = minn(a[i][2], j, m - j);
      }
      if (v[i][j] == '#') {
        a[i][2] = minn(a[i][2], j, m - j);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      for (int k = 0; k < n; k++) {
        if (j == k || k == i) continue;
        ans = min(ans, a[i][0] + a[j][1] + a[k][2]);
      }
    }
  }
  cout << ans;
  return 0;
}
