#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
bool let(char x) { return x >= 'a' && x <= 'z'; }
bool chr(char x) { return x == '#' || x == '*' || x == '&'; }
bool num(char x) { return x >= '0' && x <= '9'; }
int sum[50][3];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 50; i++)
    for (int j = 0; j < 3; j++) sum[i][j] = 999;
  char str[50][50];
  for (int i = 0; i < n; i++) scanf("%s", str[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (let(str[i][j]) && (j < sum[i][0])) {
        sum[i][0] = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (let(str[i][j]) && (m - j < sum[i][0])) {
        sum[i][0] = m - j;
        break;
      }
    for (int j = 0; j < m; j++)
      if (chr(str[i][j]) && (j < sum[i][1])) {
        sum[i][1] = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (chr(str[i][j]) && (m - j < sum[i][1])) {
        sum[i][1] = m - j;
        break;
      }
    for (int j = 0; j < m; j++)
      if (num(str[i][j]) && (j < sum[i][2])) {
        sum[i][2] = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (num(str[i][j]) && (m - j < sum[i][2])) {
        sum[i][2] = m - j;
        break;
      }
  }
  int MIN = 999999;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int k = 0; k < n; k++) {
        if (k == i || k == j) continue;
        MIN = min(MIN, sum[i][0] + sum[j][1] + sum[k][2]);
      }
    }
  cout << MIN << endl;
  return 0;
}
