#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int inf = 0x3f3f3f3f;
int n, m;
bool vis[N];
int attribute[N][4];
int ans;
string s;
void dfs(int j, int sum) {
  if (j == 3) {
    ans = min(ans, sum);
    return;
  }
  if (sum > ans) {
    return;
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      vis[i] = true;
      dfs(j + 1, sum + attribute[i][j]);
      vis[i] = false;
    }
  }
}
int main() {
  cin >> n >> m;
  memset(attribute, inf, sizeof(attribute));
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (isdigit(s[j]))
        attribute[i][0] = min(min(j, m - j), attribute[i][0]);
      else if (islower(s[j]))
        attribute[i][1] = min(min(j, m - j), attribute[i][1]);
      else
        attribute[i][2] = min(min(j, m - j), attribute[i][2]);
    }
  }
  ans = inf;
  dfs(0, 0);
  cout << ans << endl;
}
