#include <bits/stdc++.h>
using namespace std;
void read(long long a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("out", "w", stdout);
}
long long n, m;
string second[100009];
long long dp[109][109];
long long cost(char x) {
  if (x >= 'a' && x <= 'z')
    return 1;
  else if (x >= '0' && x <= '9')
    return 2;
  else
    return 4;
}
long long mm(long long x) {
  x += m;
  x %= m;
  return x;
}
long long ans(long long ind, long long bitmask) {
  if (ind == n) {
    if (bitmask == 7)
      return 0;
    else
      return 10000000;
  }
  if (dp[ind][bitmask] == -1) {
    long long tmp = ans(ind + 1, bitmask | cost(second[ind][0]));
    for (int i = 1; i < m; i++) {
      tmp = min(tmp, i + ans(ind + 1, bitmask | cost(second[ind][i])));
      tmp = min(tmp, i + ans(ind + 1, bitmask | cost(second[ind][mm(-i)])));
    }
    dp[ind][bitmask] = tmp;
  }
  return dp[ind][bitmask];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> second[i];
  memset(dp, -1, sizeof(dp));
  cout << ans(0, 0);
}
