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];
int c[16][1<<16][2];

int Max(int &a,int b){return a=max(a,b);}

int main(){

  int h,w;
  string s[128];

  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>s[i];
  for(int i=0;i<w;i++)
    for(int j=0;j<1<<w;j++){
      int cnt=0;

      for(int k=0;k<i;k++)
	cnt+=bool(j&(1<<k));
      
      c[i][j][0]=cnt;
      c[i][j][1]=__builtin_popcount(j)-cnt;
    }


  for(int i=0;i<h;i++){
    
    for(int j=0;j<w;j++)
      for(int k=0;k<1<<w;k++){
	dp[(i+1)%2][j][k]=-1e9;
      }

    for(int j=0;j<w;j++)
      for(int k=0;k<(1<<w);k++){
	int cs=0;
	
	int idx = c[j][k][0],o=(int)s[i-1].size()-c[j][k][1];
	
	if(i && k&(1<<j) && idx <(int)s[i].size() && 0<=o && o < (int)s[i-1].size() && s[i][idx] == s[i-1][o]) cs+=2;


	if(j && idx && idx < (int)s[i].size() && (k & 1<<(j-1) ) && s[i][idx -1] == s[i][idx]) cs+=2;
	
	if( j!=w-1 || idx == (int)s[i].size() -1){
	  Max(dp[(i+(j==w-1))%2][(j+1)%w][k|(1<<j)],dp[i%2][j][k]+cs);

	}
	int nk=k;
	if(k&1<<j) nk^=1<<j;
	
	if( j!=w-1 || idx == (int)s[i].size() ) Max(dp[(i+(j==w-1))%2][(j+1)%w][nk],dp[i%2][j][k]);
	
      }
  }

  int ans=0;

  for(int i=0;i<1<<w;i++)
    if((int)s[h-1].size()==c[0][i][1]){
      ans=max(ans,dp[h%2][0][i]);
    }
  
  cout<<ans<<endl;
  return 0;
}