#include <bits/stdc++.h>
using namespace std;
string s[55];
long long arr[55][5];
int che(char c) {
  if (c >= '0' && c <= '9')
    return 1;
  else if (c >= 'a' && c <= 'z')
    return 2;
  else
    return 3;
}
long long min(long long a, long long b) { return (a < b ? a : b); }
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, m, i, j, w, k, cnt;
  cin >> n >> m;
  long long ans = 1000000000000;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < 5; j++) arr[i][j] = ans;
  for (i = 0; i < n; i++) {
    cnt = 0;
    for (j = 0; j < m; j++) {
      k = che(s[i][j]);
      arr[i][k] = min(arr[i][k], cnt);
      cnt++;
    }
    cnt = 1;
    for (j = m - 1; j >= 0; j--) {
      k = che(s[i][j]);
      arr[i][k] = min(arr[i][k], cnt);
      cnt++;
    }
  }
  for (i = 0; i < n; i++) {
    for (k = 0; k < n; k++) {
      for (w = 0; w < n; w++) {
        if (i != k && k != w && i != w) {
          ans = min(ans, arr[i][1] + arr[k][2] + arr[w][3]);
          ans = min(ans, arr[i][1] + arr[k][3] + arr[w][2]);
          ans = min(ans, arr[i][2] + arr[k][1] + arr[w][3]);
          ans = min(ans, arr[i][2] + arr[k][3] + arr[w][1]);
          ans = min(ans, arr[i][3] + arr[k][1] + arr[w][2]);
          ans = min(ans, arr[i][3] + arr[k][2] + arr[w][1]);
        }
      }
    }
  }
  cout << ans << " ";
  return 0;
}
