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 dp[2][16][1<<16];
signed main(){
  int r,c;
  cin>>r>>c;
  string s[r];
  for(int i=0;i<r;i++) cin>>s[i];
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  int mask=(1<<c)-1;
  for(int i=0;i<r;i++){
    bool f=i%2;
    memset(dp[!f],-1,sizeof(dp[!f]));
    for(int j=0;j<c;j++){
      for(int b=0;b<(1<<c);b++){
	if(dp[f][j][b]<0) continue;
	//cout<<i<<" "<<j<<" "<<b<<":"<<dp[f][j][b]<<endl;
	char t,u;
	t=u='$';
	int y=0;
	for(int k=j-1;k>=0;k--) if((b>>k)&1) y++;
	if(j&&(b&1)) u=s[i][y-1];

	if(i){
	  int x=s[i-1].size()-(__builtin_popcountll(b)-y);
	  if(x<(int)s[i-1].size()&&((b>>(c-1))&1)) t=s[i-1][x];
	}
	
	if(y<(int)s[i].size()){
	  int nb=((b<<1)&mask)+1;
	  int nd=dp[f][j][b]+(t==s[i][y])*2+(u==s[i][y])*2;
	  if(j+1<c)
	    dp[f][j+1][nb]=max(dp[f][j+1][nb],nd);
	  else if(y+1==(int)s[i].size())
	    dp[!f][0][nb]=max(dp[!f][0][nb],nd);
	}
	{
	  int nb=(b<<1)&mask;
	  int nd=dp[f][j][b];
	  if(j+1<c)
	    dp[f][j+1][nb]=max(dp[f][j+1][nb],nd);
	  else if(y==(int)s[i].size())
	    dp[!f][0][nb]=max(dp[!f][0][nb],nd);
	}
      }
    }
  }
  int ans=0;
  for(int b=0;b<(1<<c);b++)
    ans=max(ans,dp[r%2][0][b]);
  cout<<ans<<endl;
  return 0;
}