#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > dist(51, vector<int>(3, 100));
int n, m;
int dp[51][8];
void calc_s(int i, string &s) {
  for (int j = 0; j < s.length(); j++) {
    if (s[j] == '#' || s[j] == '*' || s[j] == '&') {
      dist[i][2] = min(dist[i][2], j);
      dist[i][2] = min(dist[i][2], m - j);
    } else if (s[j] >= 'a' && s[j] <= 'z') {
      dist[i][0] = min(dist[i][0], j);
      dist[i][0] = min(dist[i][0], m - j);
    } else if (s[j] >= '0' && s[j] <= '9') {
      dist[i][1] = min(dist[i][1], j);
      dist[i][1] = min(dist[i][1], m - j);
    }
  }
}
int calc(int i, int j) {
  if (j == 7) return 0;
  if (i == (n + 1)) return 100;
  if (dp[i][j] != -1) return dp[i][j];
  int x = 100;
  for (int k = 0; k < 3; k++) {
    x = min(x, dist[i][k] + calc(i + 1, (j | (1 << k))));
  }
  dp[i][j] = x;
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    calc_s(i, s);
  }
  memset(dp, -1, sizeof(dp));
  cout << calc(1, 0);
  return 0;
}
