#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[55][55];
int usl(int i, string g) {
  int ch = g.find(a[i][0]);
  if (ch > -1 && ch < g.size()) return 0;
  int j = m - 1;
  int v1 = 1;
  while (j > 0) {
    int ch = g.find(a[i][j]);
    if (ch > -1 && ch < g.size()) break;
    j--;
    v1++;
  }
  if (j == 0) v1 = 1e9;
  j = 1;
  int v2 = 1;
  while (j < m) {
    int ch = g.find(a[i][j]);
    if (ch > -1 && ch < 26) break;
    v2++;
    j++;
  }
  if (j == m) v2 = 1e9;
  int mi = min(v1, v2);
  return mi;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  pair<int, int> b[n], c[n], d[n];
  for (int i = 0; i < n; i++) {
    b[i].first = usl(i, "abcdefghijklmnopqrstuvwxyz");
    c[i].first = usl(i, "0123456789");
    d[i].first = usl(i, "#*&");
    b[i].second = i;
    c[i].second = i;
    d[i].second = i;
  }
  sort(b, b + n);
  sort(c, c + n);
  sort(d, d + n);
  if (b[0].second != c[0].second && c[0].second != d[0].second &&
      d[0].second != b[0].second) {
    cout << b[0].first + c[0].first + d[0].first;
    return 0;
  }
  if (b[0].second == c[0].second && c[0].second != d[0].second &&
      d[0].second != b[0].second) {
    int o = min(b[0].first + c[1].first + d[0].first,
                b[1].first + c[0].first + d[0].first);
    cout << o;
    return 0;
  }
  if (b[0].second != c[0].second && c[0].second == d[0].second &&
      d[0].second != b[0].second) {
    int o = min(b[0].first + c[1].first + d[0].first,
                b[0].first + c[0].first + d[1].first);
    cout << o;
    return 0;
  }
  if (b[0].second != c[0].second && c[0].second != d[0].second &&
      d[0].second == b[0].second) {
    int o = min(b[0].first + c[0].first + d[1].first,
                b[1].first + c[0].first + d[0].first);
    cout << o;
    return 0;
  }
  if (b[0].second == c[0].second && c[0].second == d[0].second &&
      d[0].second == b[0].second) {
    int v1, v2, v3;
    if (b[1].second == c[1].second)
      v1 = min(b[1].first + c[2].first + d[0].first,
               b[2].first + c[1].first + d[0].first);
    else
      v1 = d[0].first + b[1].first + c[1].first;
    if (b[1].second == d[1].second)
      v2 = min(b[1].first + c[0].first + d[2].first,
               b[2].first + c[0].first + d[1].first);
    else
      v2 = c[0].first + b[1].first + d[1].first;
    if (c[1].second == d[1].second)
      v3 = min(b[0].first + c[2].first + d[1].first,
               b[0].first + c[1].first + d[2].first);
    else
      v3 = b[0].first + c[1].first + d[1].first;
    int o = min(min(v1, v2), v3);
    cout << o;
    return 0;
  }
}
