After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length _n_ which satisfies the following requirements:
* There is at least one digit in the string,
* There is at least one lowercase (small) letter of the Latin alphabet in the string,
* There is at least one of three listed symbols in the string: '_#_', '_*_', '_&_'.
<center></center>Considering that these are programming classes it is not easy to write the password.
For each character of the password we have a fixed string of length _m_, on each of these _n_ strings there is a pointer on some character. The _i_\-th character displayed on the screen is the pointed character in the _i_\-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).
During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index _m_, and when we move it to the right from the position _m_ it moves to the position 1.
You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.
## Input
The first line contains two integers _n_, _m_ (3 ≤ _n_ ≤ 50, 1 ≤ _m_ ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.
Each of the next _n_ lines contains the string which is assigned to the _i_\-th symbol of the password string. Its length is _m_, it consists of digits, lowercase English letters, and characters '_#_', '_*_' or '_&_'.
You have such input data that you can always get a valid password.
## Output
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
[samples]
## Note
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.
<center></center>In the second test one of possible algorithms will be:
* to move the pointer of the second symbol once to the right.
* to move the pointer of the third symbol twice to the right.
<center></center>
在克服楼梯后,Dasha 来到了教室。她需要输入一个密码才能开始上课。密码是一个长度为 $n$ 的字符串,满足以下要求:
考虑到这是编程课,输入密码并不容易。
对于密码的每个字符,我们都有一个固定长度为 $m$ 的字符串,每个这样的 $n$ 个字符串上都有一个指针指向某个字符。屏幕上显示的第 $i$ 个字符是第 $i$ 个字符串中指针所指向的字符。初始时,所有指针都位于对应字符串中索引为 $1$ 的字符上(所有位置从 1 开始编号)。
在一次操作中,Dasha 可以将某个字符串中的指针向左或向右移动一个字符。字符串是循环的,这意味着当指针位于索引为 $1$ 的字符上并向左移动时,它会移动到索引为 $m$ 的字符;当指针位于索引为 $m$ 的字符上并向右移动时,它会移动到索引为 $1$ 的字符。
你需要确定使屏幕上显示的字符串成为有效密码所需的最少操作次数。
第一行包含两个整数 $n$, $m$ $ (3 ≤ n ≤ 50, 1 ≤ m ≤ 50)$ —— 密码的长度和分配给密码字符的字符串的长度。
接下来的 $n$ 行每行包含一个分配给密码字符串第 $i$ 个字符的字符串。其长度为 $m$,由数字、小写英文字母以及字符 '_'、'*' 或 '&' 组成。
保证输入数据总能构造出一个有效密码。
输出一个整数 —— 使屏幕上显示的字符串成为有效密码所需的最少操作次数。
在第一个测试用例中,需要将第三个字符串的指针向左移动一次以获得最优答案。
在第二个测试用例中,一种可能的算法是:
## Input
第一行包含两个整数 $n$, $m$ $ (3 ≤ n ≤ 50, 1 ≤ m ≤ 50)$ —— 密码的长度和分配给密码字符的字符串的长度。接下来的 $n$ 行每行包含一个分配给密码字符串第 $i$ 个字符的字符串。其长度为 $m$,由数字、小写英文字母以及字符 '_'、'*' 或 '&' 组成。保证输入数据总能构造出一个有效密码。
## Output
输出一个整数 —— 使屏幕上显示的字符串成为有效密码所需的最少操作次数。
[samples]
## Note
在第一个测试用例中,需要将第三个字符串的指针向左移动一次以获得最优答案。在第二个测试用例中,一种可能的算法是:将第二个字符的指针向右移动一次;将第三个字符的指针向右移动两次。
**Definitions**
Let $ n, m \in \mathbb{Z} $ with $ 3 \leq n \leq 50 $, $ 1 \leq m \leq 50 $.
Let $ S = (s_1, s_2, \dots, s_n) $ be a tuple of strings, where each $ s_i \in \Sigma^m $ and $ \Sigma $ is the alphabet of digits, lowercase letters, and characters `'_', '*', '&'`.
Let $ p_i = 1 $ for all $ i \in \{1, \dots, n\} $ be the initial pointer position (1-indexed) on string $ s_i $.
Let $ T \in \Sigma^n $ be the target password string (unknown explicitly, but guaranteed to be constructible by moving pointers).
**Constraints**
1. Each string $ s_i $ is cyclic: moving left from position 1 goes to position $ m $, and right from position $ m $ goes to position 1.
2. The target password $ T $ must satisfy: for each $ i \in \{1, \dots, n\} $, $ T[i] \in s_i $ (i.e., the $ i $-th character of the password must be one of the characters in $ s_i $).
3. The goal is to choose $ T $ and pointer positions $ q_i \in \{1, \dots, m\} $ such that $ T[i] = s_i[q_i] $ for all $ i $, and the total movement cost is minimized.
**Objective**
Minimize the total number of operations:
$$
\min_{T \in \prod_{i=1}^n s_i} \sum_{i=1}^n \min_{q_i : s_i[q_i] = T[i]} \text{dist}(1, q_i)
$$
where $ \text{dist}(a, b) = \min(|a - b|, m - |a - b|) $ is the cyclic distance on a string of length $ m $.
Equivalently, for each string $ s_i $, define:
$$
d_i(c) = \min_{q \in \{1,\dots,m\} : s_i[q] = c} \min(|1 - q|, m - |1 - q|)
$$
Then:
$$
\min_{T \in \prod_{i=1}^n s_i} \sum_{i=1}^n d_i(T[i])
$$