#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e7;
string ss[55], s[55];
int dp[55][10];
int mp[356];
int n, m;
int rec(int pos, int mask) {
  if (pos == n) return mask == 7 ? 0 : inf;
  int &ret = dp[pos][mask];
  if (~ret) return ret;
  ret = inf;
  int pp = m;
  for (int i = 0; i < s[pos].size(); i++) {
    ret = min(ret, abs(i - m) + rec(pos + 1, (mask | mp[s[pos][i]])));
  }
  return ret;
}
int main() {
  for (int i = 'a'; i <= 'z'; i++) mp[i] = 1;
  for (int i = '0'; i <= '9'; i++) mp[i] = 2;
  mp['#'] = 4;
  mp['*'] = 4;
  mp['&'] = 4;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      cin >> ss[i];
      s[i] = ss[i];
      s[i] += ss[i];
    }
    memset(dp, -1, sizeof dp);
    cout << rec(0, 0) << "\n";
    cerr << "---\n";
  }
  return 0;
}
