#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> words;
int dp[8][51] = {};
int solve(int con, int index) {
  if (index >= n && con != 7) return 0x3f3f3f3f;
  if (con == 7) return dp[con][index] = 0;
  if (dp[con][index] != -1) return dp[con][index];
  int t, temp = 0x3f3f3f3f;
  for (int i = 0; i < m; i++) {
    t = con;
    if (words[index][i] == '&' || words[index][i] == '*' ||
        words[index][i] == '#') {
      t |= (1 << 2);
    } else if (words[index][i] >= '0' && words[index][i] <= '9') {
      t |= (1 << 1);
    } else {
      t |= (1 << 0);
    }
    temp = min(temp, min(i, m - i) + solve(t, index + 1));
  }
  return dp[con][index] = temp;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    words.push_back(s);
  }
  cout << solve(0, 0) << endl;
}
