#include <bits/stdc++.h>
using namespace std;
int sv[5000010];
void sieve() {
  for (int i = 2; i <= sqrt(5000010); i++) {
    if (sv[i] == 0) {
      sv[i] = i;
      for (int j = i * i; j < 5000010; j += i) {
        sv[j] = i;
      }
    }
  }
}
double pow_(double a, long long b) {
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    return pow_(a, b - 1) * a;
  } else {
    double x = pow_(a, b / 2);
    return x * x;
  }
}
int bin_s(vector<pair<int, int> >& v, int x) {
  int l = 0, r = v.size() - 1;
  while (l != r - 1) {
    int m = (l + r) / 2;
    if (v[m].first > x) {
      r = m;
    } else {
      l = m;
    }
  }
  if (v[r].first == x) {
    return r;
  } else if (v[l].first == x) {
    return l;
  } else {
    return -1;
  }
}
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  return (b == 0 ? a : gcd(a % b, b));
}
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(NULL));
  int n, m, ans1 = 99999999, ans2 = 9999999, ans3 = 9999999;
  cin >> n >> m;
  vector<vector<int> > v(n, vector<int>(m)), ans(n, vector<int>(3, 100000000));
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < m; j++) {
      if (str[j] >= 'a' && str[j] <= 'z') {
        ans[i][0] = min(ans[i][0], min(j, m - j));
      }
      if (str[j] >= '0' && str[j] <= '9') {
        ans[i][1] = min(ans[i][1], min(j, m - j));
      }
      if (str[j] == '*' || str[j] == '&' || str[j] == '#') {
        ans[i][2] = min(ans[i][2], min(j, m - j));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i) {
        for (int k = 0; k < n; k++) {
          if (k != j && k != i) {
            ans1 = min(ans1, ans[i][0] + ans[j][1] + ans[k][2]);
          }
        }
      }
    }
  }
  cout << ans1;
  return 0;
}
