#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 50;
string v[MAX_N];
int d[MAX_N][3];
int t[128];
int main() {
  for (char ch = 'a'; ch <= 'z'; ch++) t[ch] = 1;
  t['*'] = t['&'] = t['#'] = 2;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    d[i][0] = d[i][1] = d[i][2] = 100000;
    for (int j = 0; j < m; j++)
      d[i][t[v[i][j]]] = min(d[i][t[v[i][j]]], min(j, m - j));
  }
  int s = 100000;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        if (i != j && i != k && j != k) s = min(s, d[i][0] + d[j][1] + d[k][2]);
  cout << s;
  return 0;
}
