#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  if (a == 0) return 0;
  if (a == 1 || n == 0) return 1;
  if (n == 1) return a % 1000000007;
  long long t = power(a, n / 2);
  t = t * t % 1000000007;
  if (n & 1) return t * a % 1000000007;
  return t;
}
int popcount(long long a) {
  int c = 0;
  while (a) {
    c++;
    a -= a & -a;
  }
  return c;
}
void factorize(int a) {}
void update(int tree[], int idx, int val, int maxval) {
  for (; idx <= maxval; idx += idx & -idx) {
    tree[idx] += val;
  }
}
int read(int tree[], int idx) {
  long long sum = 0;
  for (; idx > 0; idx -= idx & -idx) {
    sum += tree[idx];
  }
  return sum;
}
struct node2 {
  int id, val;
  node2() {
    static int ctx = 1;
    id = ctx++;
  };
  node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp2 {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp2(int a, int b) { return b < a; }
struct node {
  int id, val;
  node() {
    static int ctx = 1;
    id = ctx++;
  };
  node(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp(int a, int b) { return b < a; }
int n, m, a[109][109], b, c, d, k, h, w, x, y, p, q, t, ans, res, ma, mi, T,
    act = 0, pas = 1, cur, flag, now;
int dp[109][22], table[10][109];
char s[109][109];
double e, f, z;
vector<int> v[1], vec;
set<int> sett;
map<int, int> mapp;
void print() {
  cout << "a:" << endl;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) cout << a[i][j] << " ";
    cout << endl;
  }
  cout << endl;
  cout << "table:" << endl;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 3; j++) cout << table[j][i] << " ";
    cout << endl;
  }
  cout << endl;
}
void print2() {}
inline bool check_letter(char c) { return (c >= 'a' && c <= 'z'); }
inline bool check_num(char c) { return (c >= '0' && c <= '9'); }
inline bool check_special(char c) { return (c == '#' || c == '*' || c == '&'); }
void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> m >> n;
  for (int i = 0; i < m; i++) cin >> s[i];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (check_letter(s[i][j]))
        a[i][j] = 0;
      else if (check_num(s[i][j]))
        a[i][j] = 1;
      else if (check_special(s[i][j]))
        a[i][j] = 2;
      else
        a[i][j] = 3;
    }
  }
}
void init() {
  memset(table, 0x03, sizeof(table));
  memset(dp, 0x03, sizeof(dp));
  for (int row = 0; row < m; row++) {
    for (int ptr = 0; ptr < n; ptr++) {
      int type = a[row][ptr];
      table[type][row] = min(table[type][row], min(ptr, n - ptr));
    }
  }
}
inline int calc(int j, int type) {
  if (j & (1 << type)) return j ^ (1 << type);
  return j;
}
void solve() {
  init();
  for (int type = 0; type < 3; type++) dp[0][1 << type] = table[type][0];
  dp[0][0] = 0;
  for (int i = 1; i < m; i++) {
    int lim = 8;
    for (int j = 1; j < lim; j++) {
      for (int type = 0; type < 3; type++) {
        dp[i][j | (1 << type)] =
            min(dp[i][j | (1 << type)], dp[i - 1][j] + table[type][i]);
      }
    }
  }
}
void output() { cout << dp[m - 1][7]; }
int main() {
  input();
  solve();
  output();
  return 0;
}
