#include <bits/stdc++.h>
using namespace std;
long long int n, m;
inline long long int dist(long long int x) {
  long long int a = x;
  long long int b = m - x;
  return min(a, b);
}
int main() {
  cin >> n >> m;
  char ar[n][m];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> ar[i][j];
    }
  }
  long long int d[n][3];
  for (long long int i = 0; i < n; i++) {
    d[i][0] = d[i][1] = d[i][2] = INT_MAX;
  }
  long long int ans = INT_MAX;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (isalpha(ar[i][j]))
        d[i][0] = min(d[i][0], dist(j));
      else if (isdigit(ar[i][j]))
        d[i][1] = min(d[i][1], dist(j));
      else if (ar[i][j] == '#' || ar[i][j] == '*' || ar[i][j] == '&')
        d[i][2] = min(d[i][2], dist(j));
    }
  }
  long long int ha[3] = {0, 1, 2};
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      for (long long int k = 0; k < n; k++) {
        if (i == j || j == k || k == i) continue;
        ans = min(ans, d[i][ha[0]] + d[j][ha[1]] + d[k][ha[2]]);
        ans = min(ans, d[i][ha[0]] + d[k][ha[1]] + d[j][ha[2]]);
        ans = min(ans, d[j][ha[0]] + d[i][ha[1]] + d[k][ha[2]]);
        ans = min(ans, d[j][ha[0]] + d[k][ha[1]] + d[i][ha[2]]);
        ans = min(ans, d[k][ha[0]] + d[i][ha[1]] + d[j][ha[2]]);
        ans = min(ans, d[k][ha[0]] + d[j][ha[1]] + d[i][ha[2]]);
      }
    }
  }
  cout << ans;
  return 0;
}
