#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 1e3, mod = 1e9 + 7, inf = 1e9;
long long n, m, x1, d, z, t, sum, x, y, maxi, mini, a[MAXN], dp[4][MAXN],
    b[MAXN], ans;
string s[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 4; j++) {
      dp[j][i] = inf;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] >= 'a' && s[i][j] <= 'z') {
        dp[1][i] = j;
        break;
      }
    }
    for (int j = 0; j < m; j++) {
      if (s[i][j] >= '0' && s[i][j] <= '9') {
        dp[2][i] = j;
        break;
      }
    }
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*' || s[i][j] == '#' || s[i][j] == '&') {
        dp[3][i] = j;
        break;
      }
    }
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] >= 'a' && s[i][j] <= 'z') {
        dp[1][i] = min(dp[1][i], (m - j));
        break;
      }
    }
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] >= '0' && s[i][j] <= '9') {
        dp[2][i] = min(dp[2][i], (m - j));
        break;
      }
    }
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] == '*' || s[i][j] == '#' || s[i][j] == '&') {
        dp[3][i] = min(dp[3][i], (m - j));
        break;
      }
    }
  }
  ans = inf;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (i != j && i != k && j != k) {
          ans = min(ans, dp[1][i] + dp[2][j] + dp[3][k]);
        }
      }
    }
  }
  cout << ans;
}
