Problem: You are playing a solitaire puzzle called "Connect", which uses several letter tiles.

There are R × C empty cells. For each i (1 ≤ i ≤ R), you must put a string si (1 ≤ |si| ≤ C) in the i-th row of the table, without changing the letter order. In other words, you choose an integer sequence {aj} such that 1 ≤ a1 < a2 < ... < a|si| ≤ C , and put the j-th character of the string si in the aj-th column (1 ≤ j ≤ |si|).

For example, when C = 8 and si = "ICPC", you can put si like followings.


I_C_P_C_
ICPC____
_IC___PC


'_' represents an empty cell.

For each non-empty cell x, you get a point equal to the number of adjacent cells which have the same character as x. Two cells are adjacent if they share an edge.

Calculate the maximum total point you can get.



Input

The first line contains two integers R and C (1 ≤ R ≤ 128, 1 ≤ C ≤ 16).

Then R lines follow, each of which contains si (1 ≤ |si| ≤ C). All characters of si are uppercase letters.

Output

Output the maximum total point in a line.

Examples

Input

2 4
ACM
ICPC


Output

2


Input

2 9
PROBLEMF
CONNECT


Output

6


Input

4 16
INTERNATIONAL
COLLEGIATE
PROGRAMMING
CONTEST


Output

18

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll R,C; cin >> R >> C;
    vector<string> S(R);
    for(auto& in:S) cin >> in;
    vector<int> bitcnt(1<<C);
    for(int i = 0; i < (1<<C);i++){
        bitcnt[i] = __builtin_popcount(i);
    }
    vector<vector<int>> dp(2,vector<int>(1<<C,-1));
    int cur = 0, next = 1;
    dp[cur][0] = 0;
    for(int i = 0; i < R;i++){
        for(int j = 0; j < C;j++){
            for(int k = 0; k < (1<<C);k++) dp[next][k] = -1;
            for(int k = 0; k < (1<<C);k++){
                if(dp[cur][k] == -1) continue;
                int cur_cnt = bitcnt[k&(1<<j) - 1];
                if(cur_cnt < S[i].length()){
                    int tmp = dp[cur][k];
                    if(cur_cnt > 0 && (k & 1<<(j-1))){
                        if(S[i][cur_cnt-1] == S[i][cur_cnt]) tmp++;
                    }
                    if(i > 0 && (k & (1<<j))){
                        if(S[i][cur_cnt] == S[i-1][S[i-1].length() - bitcnt[k >> j]]) tmp++;
                    }
                    dp[next][k|1<<j] = max(dp[next][k|1<<j],tmp);
                }
                if(C - j > S[i].length() - cur_cnt){
                    dp[next][k & ~(1<<j)] = max(dp[next][k & ~(1<<j)],dp[cur][k]);
                }
            }
            cur = (cur == 0)? 1:0;
            next = (next == 0)?1:0;
        }
    }
    cout <<2 * (*max_element(dp[cur].begin(), dp[cur].end())) << endl;
    return 0;
}