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;
int INF=1e9;
int R,C;
 
char s[128][20];
int len[128];
int dp[2][(1<<16)];
 
int main(){
  scanf("%d %d",&R,&C);
  for(int i=0;i<R;i++){
    scanf("%s",s[i]);
    len[i]=strlen(s[i]);
  }
   
 
  fill( (int*)dp[0], (int*)dp[2], -INF);
  dp[0][0]=0;
 
  int ai=1,bi=0;
  int ans=0;
  for(int i=0;i<=R;i++){
 
     
    for(int j=0;j<C;j++){
 
      swap(ai,bi);

      for(int bit=0;bit<(1<<C);bit++)dp[bi][bit]=-INF;
      
      for(int bit=0;bit<(1<<C);bit++){
        if(dp[ai][bit]==-INF)continue;
 
        if(i>0 && j==0 && __builtin_popcount(bit) != len[i-1])continue;
        if(i==R&&j==0)ans=max(ans,dp[ai][bit]);
         
        if(i==R)continue;
        int a=0,b=0,cost=dp[ai][bit];
        for(int k=0;k<C-j;k++)a+=(bit>>k&1);
        for(int k=C-j;k<C;k++)b+=(bit>>k&1);
         
        int nbit=bit>>1;
        dp[bi][nbit]=max(dp[bi][nbit],cost);
         
 
        if(b==len[i])continue;
         
        int flg=0;
        if(bit&1 && s[i][b]==s[i-1][len[i-1]-a])flg++;
        if(bit>>(C-1)&1)
          if(b>0&&s[i][b-1]==s[i][b])flg++;
         
        nbit=(bit|(1<<C))>>1;
        dp[bi][nbit]=max(dp[bi][nbit],cost+flg);
   
      }
    }
  }
  cout<<ans*2<<endl;
       
  return 0;
}