#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
int type(char c) {
  if (isalpha(c)) return 0;
  if (isdigit(c))
    return 1;
  else
    return 2;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> vec(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> vec[i];
  vector<vector<int> > dp(n + 1, vector<int>(8, 2147483600));
  dp[0][0] = 0;
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(8); j++)
      if (dp[i][j] < 2147483600) {
        for (int k = (int)(0); k < (int)(m); k++) {
          int t = type(vec[i][k]);
          dp[i + 1][j | (1 << t)] =
              min(dp[i + 1][j | (1 << t)], dp[i][j] + min(k, m - k));
        }
      }
  cout << dp[n][7] << endl;
  return 0;
}
