#include <bits/stdc++.h>
using namespace std;
int n, m, f1[55], f2[55], f3[55], ans = 1e9;
string str[55];
inline bool iss(char c) { return (c == '#' || c == '*' || c == '&'); }
inline bool isd(char c) { return (c <= '9' && c >= '0'); }
inline bool isl(char c) { return (c <= 'z' && c >= 'a'); }
inline void init(int x) {
  vector<int> v1, v2, v3;
  for (int i = 0; i < m; i++) {
    if (iss(str[x][i])) v1.push_back(i);
    if (isd(str[x][i])) v2.push_back(i);
    if (isl(str[x][i])) v3.push_back(i);
  }
  f1[x] = (v1.size() == 0 ? -1 : min(v1[0], m - v1[v1.size() - 1]));
  f2[x] = (v2.size() == 0 ? -1 : min(v2[0], m - v2[v2.size() - 1]));
  f3[x] = (v3.size() == 0 ? -1 : min(v3[0], m - v3[v3.size() - 1]));
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> str[i];
  for (int i = 1; i <= n; i++) init(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      for (int k = 1; k <= n; k++) {
        if (i == k || j == k) continue;
        if (f1[i] == -1 || f2[j] == -1 || f3[k] == -1) continue;
        ans = min(ans, f1[i] + f2[j] + f3[k]);
      }
    }
  }
  cout << ans;
  return 0;
}
