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>
#define N 130
#define C 16
using namespace std;
typedef pair<int,int> P;

int r, c, dp[2][C][(1<<C)];
P memo[C][(1<<C)];
string s[N];

void init(){
  
  for(int i=0;i<c;i++)
    
    for(int j=0;j<(1<<c);j++){

      int cnt=0;
      for(int k=0;k<i;k++)
	if(j&(1<<k)) cnt++;
      memo[i][j].first=cnt;
      
      cnt=0;
      for(int k=i;k<c;k++)
	if(j&(1<<k)) cnt++;
      memo[i][j].second=cnt;
      
    }

}

int main(){
  
  cin>>r>>c;
  
  for(int i=0;i<r;i++) cin>>s[i];

  init();
  
  memset(dp,-1,sizeof(dp));
  
  dp[0][0][0]=0;
  
  for(int i=0;i<r;i++){

    for(int j=0;j<c;j++)
      for(int k=0;k<(1<<c);k++) dp[(i+1)%2][j][k]=-1;
    
    for(int j=0;j<c;j++){
      
      for(int k=0;k<(1<<c);k++){
	
	if(dp[i%2][j][k]==-1) continue;
	
	if(memo[j][k].first<s[i].size()){
	  
	  int cost=dp[i%2][j][k], nk=k|(1<<j);
	  
	  if(i&&(k&(1<<j))&&s[i][memo[j][k].first]==s[i-1][s[i-1].size()-memo[j][k].second]) cost+=2;
	  
	  if(j&&(k&(1<<(j-1)))&&s[i][memo[j][k].first]==s[i][memo[j][k].first-1]) cost+=2;
	  
	  if(j==c-1&&memo[j][k].first+1==s[i].size()) dp[(i+1)%2][0][nk]=max(dp[(i+1)%2][0][nk],cost);
	  if(j!=c-1) dp[i%2][j+1][nk]=max(dp[i%2][j+1][nk],cost);
	  
	}

	int nk=k&~(1<<j);
	
	if(j==c-1&&memo[0][nk].second==s[i].size()) dp[(i+1)%2][0][nk]=max(dp[(i+1)%2][0][nk],dp[i%2][j][k]);
	if(j!=c-1) dp[i%2][j+1][nk]=max(dp[i%2][j+1][nk],dp[i%2][j][k]);
	
      }
      
    }
    
  }
  
  int ans=0;
  
  for(int i=0;i<(1<<c);i++) ans=max(ans,dp[r%2][0][i]);

  cout<<ans<<endl;
    
  return 0;
}