#include <bits/stdc++.h>
using namespace std;
const int M = 110, mod = 1000000007;
int typ(char c) {
  if (c >= 'a' && c <= 'z')
    return 0;
  else if (c >= '0' && c <= '9')
    return 1;
  else
    return 2;
}
int dist[M][5];
char A[M];
int dp[M][2][2][2], n;
int call(int i, int let, int dig, int bal) {
  if (i == n) return (let && dig && bal) ? 0 : 11111111;
  if (dp[i][let][dig][bal] != -1) return dp[i][let][dig][bal];
  int j, minn = 11111111;
  for (j = 0; j < 3; j++) {
    int temp = dist[i][j] +
               call(i + 1, let | (j == 0), dig | (j == 1), bal | (j == 2));
    minn = min(minn, temp);
  }
  return dp[i][let][dig][bal] = minn;
}
int main() {
  ios_base::sync_with_stdio(false);
  int m, i, j, k;
  memset((dp), (-1), sizeof(dp));
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 5; j++) dist[i][j] = 11111111;
    scanf("%s", A);
    for (j = 0; j < m; j++) {
      k = typ(A[j]);
      dist[i][k] = min(dist[i][k], min(j, m - j));
    }
  }
  k = call(0, 0, 0, 0);
  printf("%d\n", k);
  return 0;
}
