#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char a[n][m];
  int dp[n][3];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i][j] = m;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if ('0' <= a[i][j] && a[i][j] <= '9')
        dp[i][0] = min({dp[i][0], j, m - j});
      else if ('a' <= a[i][j] && a[i][j] <= 'z')
        dp[i][1] = min({dp[i][1], j, m - j});
      else
        dp[i][2] = min({dp[i][2], j, m - j});
    }
  }
  int b[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    b[i] = *min_element(dp[i], dp[i] + 3);
    sum += b[i];
  }
  int res = INT_MAX;
  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;
        if (dp[i][0] == m || dp[j][1] == m || dp[k][2] == m) continue;
        int tm = sum;
        tm -= b[i] + b[j] + b[k];
        tm += dp[i][0] + dp[j][1] + dp[k][2];
        res = min(res, tm);
      }
    }
  }
  cout << res << endl;
}
