#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int tab[50][50];
  int dists[50][3];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      char c = s[j];
      if (c >= '0' && c <= '9') {
        tab[i][j] = 0;
      } else if (c >= 'a' && c <= 'z') {
        tab[i][j] = 1;
      } else {
        tab[i][j] = 2;
      }
    }
    dists[i][0] = 100;
    dists[i][1] = 100;
    dists[i][2] = 100;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int d = min(j, m - j);
      if (d < dists[i][tab[i][j]]) {
        dists[i][tab[i][j]] = d;
      }
    }
  }
  int ans = 1000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      for (int k = 0; k < n; k++) {
        if (k == j) continue;
        int sum = dists[i][0] + dists[j][1] + dists[k][2];
        if (sum < ans) {
          ans = sum;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
