#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e18;
const long long N = 2e5 + 2;
int64_t dp[100][4];
void solve() {
  int64_t n, m;
  cin >> n >> m;
  char a[n + 10][m + 10];
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      cin >> a[i][j];
    }
    for (int64_t k = 0; k < 4; k++) dp[i][k] = 1000;
  }
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      if (a[i][j] <= '9' && a[i][j] >= '0')
        dp[i][1] = min(dp[i][1], min(j, m - j));
      else if (a[i][j] <= 'z' && a[i][j] >= 'a')
        dp[i][2] = min(dp[i][2], min(j, m - j));
      else
        dp[i][3] = min(dp[i][3], min(j, m - j));
    }
  }
  int64_t ans = INT_MAX;
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = i + 1; j < n; j++) {
      for (int64_t k = j + 1; k < n; k++) {
        for (int64_t x = 1; x <= 3; x++) {
          for (int64_t y = 1; y <= 3; y++) {
            for (int64_t z = 1; z <= 3; z++) {
              if (x == y || y == z || z == x) continue;
              ans = min(ans, dp[i][x] + dp[j][y] + dp[k][z]);
            }
          }
        }
      }
    }
  }
  cout << ans;
}
signed main() {
  int64_t t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
}
