#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mx = 1000;
  string ss;
  int dp[55][3]{};
  int sm[55][3]{};
  scanf("%i %i", &n, &m);
  for (int i = 0; i < 55; i++)
    for (int j = 0; j < 3; j++) dp[i][j] = mx, sm[i][j] = mx;
  for (int i = 0; i < n; i++) {
    cin >> ss;
    int j = 0, mn = mx;
    for (char s : ss) {
      mn = min(j, m - j);
      if (s >= 48 and s <= 57)
        dp[i][0] = min(dp[i][0], mn);
      else if (s >= 97 and s <= 122)
        dp[i][1] = min(dp[i][1], mn);
      else
        dp[i][2] = min(dp[i][2], mn);
      j++;
    }
  }
  int r = mx;
  for (int i = 0; i < 55; i++) {
    for (int j = 0; j < 55; j++) {
      if (j == i) continue;
      for (int g = 0; g < 55; g++) {
        if (j == g or i == g) continue;
        r = min(r, dp[i][0] + dp[j][1] + dp[g][2]);
        r = min(r, dp[i][0] + dp[j][2] + dp[g][1]);
        r = min(r, dp[i][1] + dp[j][0] + dp[g][2]);
        r = min(r, dp[i][1] + dp[j][2] + dp[g][0]);
        r = min(r, dp[i][2] + dp[j][1] + dp[g][0]);
        r = min(r, dp[i][2] + dp[j][0] + dp[g][1]);
      }
    }
  }
  printf("%i \n", r);
  return 0;
}
