#include <bits/stdc++.h>
using namespace std;
const int oo = int(2e9) + 9;
const double eps = 1e-9;
const double pi = 3.14159265358979323846264338327950;
int grid[105][105];
int n, m;
int memo[55][55][5][5][5];
int dp(int x, int y, int c1, int c2, int c3) {
  if (x > n || x < 1 || y > m || y < 1) return oo;
  if (memo[x][y][c1][c2][c3] != -1) return memo[x][y][c1][c2][c3];
  if (grid[x][y] == 0) c1 = max(int(c1 != 0), 1);
  if (grid[x][y] == 1) c2 = max(int(c2 != 0), 1);
  if (grid[x][y] == 2) c3 = max(int(c3 != 0), 1);
  if (x == n && c1 && c2 && c3) return 0;
  int val2 = oo;
  for (int i = 1; i <= m; i++) {
    val2 = min(val2, min(i - 1, m - i + 1) + dp(x + 1, i, c1, c2, c3));
  }
  return memo[x][y][c1][c2][c3] = val2;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < str.size(); j++) {
      if (str[j] >= '0' && str[j] <= '9') grid[i][j + 1] = 0;
      if (str[j] >= 'a' && str[j] <= 'z') grid[i][j + 1] = 1;
      if (str[j] == '#' || str[j] == '*' || str[j] == '&') grid[i][j + 1] = 2;
    }
  }
  memset(memo, -1, sizeof(memo));
  int ans = oo;
  for (int i = 1; i <= m; i++)
    ans = min(ans, min(i - 1, m - i + 1) + dp(1, i, 0, 0, 0));
  cout << ans << endl;
  return 0;
}
