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;

using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
void cmax(int &lhs,int rhs){
    lhs=max(lhs,rhs);
}
const int INF=1e5;
int main(){
    int r,c;
    cin>>r>>c;
    
    vector<string> s(r+1);
    for(int i=0;i<r;i++) cin>>s[i+1];
    vvi dp(c+1,vi(1<<c,-INF));
    dp[0][0]=0;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            for(int bit=0;bit<(1<<c);bit++){
                int upperc=__builtin_popcount((((1<<(c-j))-1)&bit));
                int posu=(int)(s[i].size())-upperc;
                int posn=(int)(__builtin_popcount(bit))-upperc;
                if(posu<0 || posu>s[i].size() || posn<0 || posn>s[i+1].size()) continue;
                int nextbit=bit>>1;
                cmax(dp[j+1][nextbit],dp[j][bit]);
                if(posn<s[i+1].size()){
                    nextbit|=(1<<(c-1));
                    if((bit&1) && s[i][posu]==s[i+1][posn]){
                        cmax(dp[j+1][nextbit],dp[j][bit]+1);
                    }
                    else{
                        cmax(dp[j+1][nextbit],dp[j][bit]);
                    }
                }
            }
        }
        for(int bit=0;bit<(1<<c);bit++){
            if(__builtin_popcount(bit)!=s[i+1].size()) dp[c][bit]=-INF;
            else{
                int idx=0;
                for(int j=0;j<c;j++){
                    if(((bit>>j)&1) && ((bit>>(j+1))&1) && s[i+1][idx]==s[i+1][idx+1]){
                        dp[c][bit]++;
                    }                    
                    if((bit>>j)&1) idx++;
                }
            }
            dp[0][bit]=dp[c][bit];
        }
        for(int j=1;j<=c;j++){
            fill(dp[j].begin(),dp[j].end(),-INF);
        }
    }
    cout<<*max_element(dp[0].begin(),dp[0].end())*2<<endl;
    return 0;
}