#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  int i, j, k;
  string passStrings[n];
  for (i = 0; i < n; i++) {
    cin >> passStrings[i];
  }
  int nearestOnes[n][3];
  memset(nearestOnes, -1, sizeof(nearestOnes));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (passStrings[i][j] >= 97 && passStrings[i][j] <= 122) {
        if (j < (m - j)) {
          if (nearestOnes[i][0] == -1 || nearestOnes[i][0] > j)
            nearestOnes[i][0] = j;
        } else {
          if (nearestOnes[i][0] == -1 || nearestOnes[i][0] > (m - j))
            nearestOnes[i][0] = m - j;
        }
      } else if (passStrings[i][j] >= 48 && passStrings[i][j] <= 57) {
        if (j < (m - j)) {
          if (nearestOnes[i][1] == -1 || nearestOnes[i][1] > j)
            nearestOnes[i][1] = j;
        } else {
          if (nearestOnes[i][1] == -1 || nearestOnes[i][1] > (m - j))
            nearestOnes[i][1] = m - j;
        }
      } else {
        if (j < (m - j)) {
          if (nearestOnes[i][2] == -1 || nearestOnes[i][2] > j)
            nearestOnes[i][2] = j;
        } else {
          if (nearestOnes[i][2] == -1 || nearestOnes[i][2] > (m - j))
            nearestOnes[i][2] = m - j;
        }
      }
    }
  }
  int minm;
  minm = INT_MAX;
  k = 0;
  int x;
  int sum1 = 0, sum2 = 0, sum3 = 0;
  for (i = 0; i < n; i++) {
    if (nearestOnes[i][0] == -1) continue;
    sum1 = nearestOnes[i][0];
    for (j = 0; j < n; j++) {
      if (i == j || nearestOnes[j][1] == -1) continue;
      sum2 = sum1 + nearestOnes[j][1];
      for (k = 0; k < n; k++) {
        if (k == i || k == j || nearestOnes[k][2] == -1) continue;
        sum3 = sum2 + nearestOnes[k][2];
        if (sum3 < minm) minm = sum3;
      }
    }
  }
  cout << minm;
}
