#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double EPS = 1e-10;
const double LEPS = 1e-15;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int dx2[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy2[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx3[] = {-1, 1, 0, 0, 0, 0};
int dy3[] = {0, 0, 1, -1, 0, 0};
int dz3[] = {0, 0, 0, 0, 1, -1};
int n, m;
string h[55];
int k[55][3];
int q, w, e;
long long dp[55][2][2][2];
long long found(int idx, int p, int w, int e) {
  if (idx == n && p && w && e) {
    return 0;
  }
  if (idx >= n) return inf;
  long long &ret = dp[idx][p][w][e];
  if (ret != -1) return ret;
  ret = inf;
  if (!p) ret = min(ret, found(idx + 1, p + 1, w, e) + k[idx][0]);
  if (!w) ret = min(ret, found(idx + 1, p, w + 1, e) + k[idx][1]);
  if (!e) ret = min(ret, found(idx + 1, p, w, e + 1) + k[idx][2]);
  ret = min(ret, found(idx + 1, p, w, e));
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    k[i][0] = k[i][1] = k[i][2] = inf;
    for (int j = 0; j < m; j++) {
      if (isalpha(h[i][j]))
        k[i][0] = min(k[i][0], min(j, m - j));
      else if (isdigit(h[i][j]))
        k[i][1] = min(k[i][1], min(j, m - j));
      else
        k[i][2] = min(k[i][2], min(j, m - j));
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << found(0, 0, 0, 0);
}
