#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, l, ans;
  char ch;
  vector<vector<char> > v;
  vector<vector<int> > z;
  cin >> n >> m;
  v.resize(n);
  z.resize(n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> ch;
      v[i].push_back(ch);
    }
  }
  for (i = 0; i < n; i++) {
    z[i].push_back(55);
    z[i].push_back(55);
    z[i].push_back(55);
    for (j = 0; j < m; j++) {
      if (v[i][j] >= 48 && v[i][j] <= 57) {
        z[i][0] = min(z[i][0], min(j, m - j));
      } else if (v[i][j] >= 97 && v[i][j] <= 122) {
        z[i][1] = min(z[i][1], min(j, m - j));
      } else {
        z[i][2] = min(z[i][2], min(j, m - j));
      }
    }
  }
  ans = 100000000;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      for (k = 0; k < n; k++) {
        if (i != j && j != k && k != i) {
          ans = min(ans, z[i][0] + z[j][1] + z[k][2]);
        }
      }
    }
  }
  cout << ans;
}
