#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int dp[55][8];
const int inf = 0x3f3f3f3f;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i]);
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 8; j++) {
      dp[i][j] = dp[i - 1][j];
    }
    for (int j = 0; j < m; j++) {
      if (a[i][j] >= '0' && a[i][j] <= '9') {
        for (int k = 0; k < 4; k++) {
          dp[i][k + 4] = min(dp[i][k + 4], dp[i - 1][k] + min(j, m - j));
        }
      } else if (a[i][j] >= 'a' && a[i][j] <= 'z') {
        dp[i][2] = min(dp[i][2], dp[i - 1][0] + min(j, m - j));
        dp[i][3] = min(dp[i][3], dp[i - 1][1] + min(j, m - j));
        dp[i][6] = min(dp[i][6], dp[i - 1][4] + min(j, m - j));
        dp[i][7] = min(dp[i][7], dp[i - 1][5] + min(j, m - j));
      } else if (a[i][j] == '#' || a[i][j] == '&' || a[i][j] == '*') {
        dp[i][1] = min(dp[i][1], dp[i - 1][0] + min(j, m - j));
        dp[i][3] = min(dp[i][3], dp[i - 1][2] + min(j, m - j));
        dp[i][5] = min(dp[i][5], dp[i - 1][4] + min(j, m - j));
        dp[i][7] = min(dp[i][7], dp[i - 1][6] + min(j, m - j));
      }
    }
  }
  printf("%d\n", dp[n][7]);
}
