#include <bits/stdc++.h>
using namespace std;
int n, m;
char arr[55][55];
int dp[55][55][55][55];
int f(int ind, int let, int dig, int sim) {
  if (ind == n) {
    if (let && dig && sim)
      return 0;
    else
      return 1e9;
  }
  if (dp[ind][let][dig][sim] != -1) return dp[ind][let][dig][sim];
  int &ret = dp[ind][let][dig][sim];
  ret = 1e9;
  for (int i = 0; i < m; i++) {
    if (arr[ind][i] >= 'a' && arr[ind][i] <= 'z')
      ret = min(ret, f(ind + 1, let + 1, dig, sim) + min(i, m - i));
    else if (arr[ind][i] >= '0' && arr[ind][i] <= '9')
      ret = min(ret, f(ind + 1, let, dig + 1, sim) + min(i, m - i));
    else
      ret = min(ret, f(ind + 1, let, dig, sim + 1) + min(i, m - i));
  }
  return ret;
}
int main() {
  while (scanf("%d %d", &n, &m) == 2) {
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; i++) scanf("%s", &arr[i]);
    int ans = f(0, 0, 0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
