#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int N = 1e12;
string a[105];
int dp1[105], dp2[105], dp3[105];
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    dp1[i] = maxn;
    dp2[i] = maxn;
    dp3[i] = maxn;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] >= 'a' && a[i][j] <= 'z')
        dp1[i] = min(dp1[i], min(j, m - j));
      else if (a[i][j] >= '0' && a[i][j] <= '9')
        dp2[i] = min(dp2[i], min(j, m - j));
      else
        dp3[i] = min(dp3[i], min(j, m - j));
    }
  }
  int ans = INT_MAX;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      for (k = 0; k < n; k++) {
        if (i != j && j != k && i != k)
          ans = min(ans, dp1[i] + dp2[j] + dp3[k]);
      }
    }
  }
  cout << ans;
  return 0;
}
