#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int64_t n, m;
  cin >> n >> m;
  string s[n];
  for (int64_t i = 0; i < n; i++) {
    cin >> s[i];
  }
  int64_t d[n + 1][2][2][2];
  memset(d, 0x3F, sizeof(d));
  d[0][0][0][0] = 0;
  for (int64_t i = 0; i < n; i++) {
    for (int64_t a = 0; a <= 1; a++) {
      for (int64_t b = 0; b <= 1; b++) {
        for (int64_t c = 0; c <= 1; c++) {
          for (int64_t j = 0; j < m; j++) {
            int64_t na = a || isdigit(s[i][j]);
            int64_t nb = b || isalpha(s[i][j]);
            int64_t nc =
                c || s[i][j] == '#' || s[i][j] == '*' || s[i][j] == '&';
            d[i + 1][na][nb][nc] =
                min(d[i + 1][na][nb][nc], d[i][a][b][c] + min(j, m - j));
          }
        }
      }
    }
  }
  cout << d[n][1][1][1] << endl;
  return 0;
}
