#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int sum = 1e6;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (i == j || j == k || k == i) continue;
        int tsum = 0;
        int temp1 = -1, temp2 = -1, temp3 = -1;
        for (int l = 0; l < m; l++) {
          if (isalpha(arr[i][l])) {
            temp1 = l;
            break;
          }
          if (isalpha(arr[i][m - 1 - l])) {
            temp1 = l + 1;
            break;
          }
        }
        for (int l = 0; l < m; l++) {
          if (isdigit(arr[j][l])) {
            temp2 = l;
            break;
          }
          if (isdigit(arr[j][m - 1 - l])) {
            temp2 = l + 1;
            break;
          }
        }
        for (int l = 0; l < m; l++) {
          if (arr[k][l] == '*' || arr[k][l] == '#' || arr[k][l] == '&') {
            temp3 = l;
            break;
          }
          if (arr[k][m - l - 1] == '*' || arr[k][m - l - 1] == '#' ||
              arr[k][m - l - 1] == '&') {
            temp3 = l + 1;
            break;
          }
        }
        if (temp1 != -1 && temp2 != -1 && temp3 != -1) {
          if (temp1 > m / 2) temp1 = m - temp1;
          if (temp2 > m / 2) temp2 = m - temp2;
          if (temp3 > m / 2) temp3 = m - temp3;
          tsum = temp1 + temp2 + temp3;
          if (tsum < sum) sum = tsum;
        }
      }
    }
  }
  cout << sum << "\n";
}
