#include <bits/stdc++.h>
using namespace std;
const int inf = 100005;
int n, m;
int digit[55][55], lower[55][55], spe[55][55];
int main() {
  cin >> n >> m;
  for (int i = 0; i <= 50; i++)
    for (int j = 0; j <= 50; j++) digit[i][j] = lower[i][j] = spe[i][j] = inf;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[m - 1] >= '0' && s[m - 1] <= '9')
      digit[i][m - 1] = m - 1;
    else if (s[m - 1] >= 'a' && s[m - 1] <= 'z')
      lower[i][m - 1] = m - 1;
    else
      spe[i][m - 1] = m - 1;
    for (int j = m - 2; j >= 0; j--) {
      if (s[j] >= '0' && s[j] <= '9')
        digit[i][j] = j;
      else if (s[j] >= 'a' && s[j] <= 'z')
        lower[i][j] = j;
      else
        spe[i][j] = j;
      digit[i][j] = min(digit[i][j], digit[i][j + 1]);
      lower[i][j] = min(lower[i][j], lower[i][j + 1]);
      spe[i][j] = min(spe[i][j], spe[i][j + 1]);
    }
    for (int j = m - 1; j >= 0; j--) {
      if (s[j] >= '0' && s[j] <= '9')
        digit[i][0] = min(digit[i][0], m - j);
      else if (s[j] >= 'a' && s[j] <= 'z')
        lower[i][0] = min(lower[i][0], m - j);
      else
        spe[i][0] = min(spe[i][0], m - j);
    }
  }
  int ans = inf;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++) {
        ans = min(ans, digit[i][0] + lower[j][0] + spe[k][0]);
        ans = min(ans, digit[i][0] + lower[k][0] + spe[j][0]);
        ans = min(ans, digit[j][0] + lower[i][0] + spe[k][0]);
        ans = min(ans, digit[j][0] + lower[k][0] + spe[i][0]);
        ans = min(ans, digit[k][0] + lower[i][0] + spe[j][0]);
        ans = min(ans, digit[k][0] + lower[j][0] + spe[i][0]);
      }
  cout << ans << endl;
  return 0;
}
