#include <bits/stdc++.h>
using namespace std;
vector<string> v(50);
int n, m;
bool val(char c, int t) {
  if (t == 1) return ('0' <= c && c <= '9');
  if (t == 2) return ('a' <= c && c <= 'z');
  return (c == '#' || c == '*' || c == '&');
}
int buscar(int pos, int t) {
  if (val(v[pos][0], t)) return 0;
  for (int i = 1; i < m / 2 + 1; i++)
    if (val(v[pos][i], t) || val(v[pos][m - i], t)) return i;
  return -1;
}
int dp[50][2][2][2];
int f(int pos, int d, int l, int s) {
  if (d + l + s == 0) return 0;
  if (pos < 0) return 2500;
  if (dp[pos][d][l][s] != -1) return dp[pos][d][l][s];
  int ans = 2500, op;
  op = buscar(pos, 1);
  if (op != -1) ans = min(ans, op + f(pos - 1, 0, l, s));
  op = buscar(pos, 2);
  if (op != -1) ans = min(ans, op + f(pos - 1, d, 0, s));
  op = buscar(pos, 3);
  if (op != -1) ans = min(ans, op + f(pos - 1, d, l, 0));
  return dp[pos][d][l][s] = ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> v[i];
  memset(dp, -1, sizeof dp);
  cout << f(n - 1, 1, 1, 1);
  return 0;
}
