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 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;}

const int BEET=-1001001001;

int H,W;
string S[222];

int dp[2][1<<16];
int pc[1<<16];
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);

    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),BEET);
    dp[0][0]=0;
    int mask=(1<<W)-1;
    for(int t=0;t<H*W;t++){
            const int i=t/W,j=t%W,p=t&1,q=(t+1)&1;
            const int beet=(1<<(W-1));
            const int ei=(1<<W);
            const int mask2=(1<<j)-1;
            const int len=S[i].size();
            const int len2=S[i+1].size();

            for(int k=0;k<beet;k++){
                if(dp[p][k]==BEET)continue;
                chmax(dp[q][(k<<1)&mask],dp[p][k]);

                int l=pc[k&mask2];
                if(l<len2){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    chmax(dp[q][((k<<1)&mask)+1],dp[p][k]+po*2);
                }
                dp[p][k]=BEET;
            }

            for(int k=beet;k<ei;k++){
                if(dp[p][k]==BEET)continue;
                chmax(dp[q][(k<<1)&mask],dp[p][k]);

                int l=pc[k&mask2];
                if(l<len2){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    if(S[i][len-pc[k]+l]==S[i+1][l])po++;
                    chmax(dp[q][((k<<1)&mask)+1],dp[p][k]+po*2);
                }
                dp[p][k]=BEET;
            }

        if(j==W-1)for(int k=0;k<ei;k++)if(pc[k]!=len2)dp[q][k]=BEET;
    }

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