#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <climits>
#include <map>
#include <set>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <deque>
#include <string>
#include <sstream>
#include <cstdlib>
#include <unordered_set>
#include <unordered_map>
using namespace std;
string v[55];
int dp[55][2][2][2];
int n,m;
int f(int pos, bool vw, bool dg, bool sb){
if(pos == n){
if(vw+dg+sb == 3) return 0;
else return 1e9;
}
if(dp[pos][vw][dg][sb] != -1) return dp[pos][vw][dg][sb];
int ans = 1e9;
for (int i = 0; i < (int)v[pos].size(); ++i){
string x = v[pos];
int sz = x.size();
if(x[i]-'a' >= 0 and x[i]-'a'<= 27) ans = min(ans,f(pos+1,true,dg,sb)+min(i,sz-i));
if(isdigit(x[i])) ans = min(ans,f(pos+1,vw,true,sb)+min(i,sz-i));
if(x[i] == '#' or x[i] == '*' or x[i] == '&')
ans = min(ans,f(pos+1,vw,dg,true)+min(i,sz-i));
}
return dp[pos][vw][dg][sb] = ans;
}
int main(){
memset(dp,-1,sizeof dp);
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> v[i];
cout << f(0,0,0,0) << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGNsaW1pdHM+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxjYXNzZXJ0PgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxzdHJpbmc+IAojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDx1bm9yZGVyZWRfc2V0PgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgdls1NV07CmludCBkcFs1NV1bMl1bMl1bMl07CmludCBuLG07CmludCBmKGludCBwb3MsIGJvb2wgdncsIGJvb2wgZGcsIGJvb2wgc2IpewogICAgaWYocG9zID09IG4pewogICAgICAgIGlmKHZ3K2RnK3NiID09IDMpIHJldHVybiAwOwogICAgICAgIGVsc2UgcmV0dXJuIDFlOTsKICAgIH0KCiAgICBpZihkcFtwb3NdW3Z3XVtkZ11bc2JdICE9IC0xKSByZXR1cm4gZHBbcG9zXVt2d11bZGddW3NiXTsKICAgIGludCBhbnMgPSAxZTk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IChpbnQpdltwb3NdLnNpemUoKTsgKytpKXsKICAgICAgICBzdHJpbmcgeCA9IHZbcG9zXTsKICAgICAgICBpbnQgc3ogPSB4LnNpemUoKTsKICAgICAgICBpZih4W2ldLSdhJyA+PSAwIGFuZCB4W2ldLSdhJzw9IDI3KSAgYW5zID0gbWluKGFucyxmKHBvcysxLHRydWUsZGcsc2IpK21pbihpLHN6LWkpKTsKICAgICAgICBpZihpc2RpZ2l0KHhbaV0pKSBhbnMgPSBtaW4oYW5zLGYocG9zKzEsdncsdHJ1ZSxzYikrbWluKGksc3otaSkpOwogICAgICAgIGlmKHhbaV0gPT0gJyMnIG9yIHhbaV0gPT0gJyonIG9yIHhbaV0gPT0gJyYnKQogICAgICAgICAgICBhbnMgPSBtaW4oYW5zLGYocG9zKzEsdncsZGcsdHJ1ZSkrbWluKGksc3otaSkpOwogICAgfQogICAgcmV0dXJuIGRwW3Bvc11bdnddW2RnXVtzYl0gPSBhbnM7Cn0KaW50IG1haW4oKXsKICAgIG1lbXNldChkcCwtMSxzaXplb2YgZHApOwogICAgY2luID4+IG4gPj4gbTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSBjaW4gPj4gdltpXTsKICAgIGNvdXQgPDwgZigwLDAsMCwwKSA8PCAiXG4iOwogICAgcmV0dXJuIDA7Cn0=