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;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
string S[222];

int dp[2][1<<16];
int pc[1<<16];
signed main(){
    for(int i=0;i<1<<16;i++)pc[i]=__builtin_popcount(i);
    cin>>H>>W;
    S[0]="";
    rep(i,H)cin>>S[i+1];

    fill_n(*dp,2*(1<<16),INT_MIN);
    dp[0][0]=0;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<(1<<W);k++){
                if(dp[(i*W+j)&1][k]==INT_MIN)continue;
                chmax(dp[(i*W+j+1)&1][(k<<1)&((1<<W)-1)],dp[(i*W+j)&1][k]);

                int l=pc[k&((1<<j)-1)];
                if(l<S[i+1].size()){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    if(k>>(W-1)&1){
                        int m=pc[k]-l;
                        m=S[i].size()-m;
                        if(S[i][m]==S[i+1][l])po++;
                    }
                    chmax(dp[(i*W+j+1)&1][((k<<1)&((1<<W)-1))+1],dp[(i*W+j)&1][k]+po*2);
                }

                dp[(i*W+j)&1][k]=INT_MIN;
            }
        }
        for(int j=0;j<1<<W;j++)if(pc[j]!=S[i+1].size())dp[(i*W+W)&1][j]=INT_MIN;
    }

    int ans=INT_MIN;
    rep(i,1<<W)chmax(ans,dp[(H*W)&1][i]);
    cout<<ans<<endl;
    return 0;
}