#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 55;
int n;
int m;
int dp[MAXN][3];
char s[MAXN][MAXN];
void getDp() {
  for (int i = 0; i < n; ++i) {
    dp[i][0] = dp[i][1] = dp[i][2] = MAXN;
    for (int j = 0; j < m; ++j) {
      int d = min(j, m - j);
      if (s[i][j] >= '0' && s[i][j] <= '9') {
        dp[i][0] = min(dp[i][0], d);
      } else if (s[i][j] == '#' || s[i][j] == '*' || s[i][j] == '&') {
        dp[i][2] = min(dp[i][2], d);
      } else {
        dp[i][1] = min(dp[i][1], d);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  getDp();
  int tempAns = MAXN * 3;
  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) {
          tempAns = min(tempAns, dp[i][0] + dp[j][1] + dp[k][2]);
        }
      }
    }
  }
  printf("%d\n", tempAns);
  return 0;
}
