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<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int len[128];
int dp[2][1<<16];
char str[128][17];
int L[16][1<<16];
int R[16][1<<16];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",str[i]);
		len[i]=strlen(str[i]);
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<(1<<b);j++){
			for(int k=0;k<b;k++)
				if(j&(1<<k)){
					if(k<i)L[i][j]++;
					else R[i][j]++;
				}
		}
	}
	int u=0;
	int mask=(1<<b)-1;
	int inf=99999999;
	for(int i=1;i<(1<<b);i++)dp[u][i]=-inf;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			for(int k=0;k<(1<<b);k++)dp[!u][k]=-inf;
			for(int k=0;k<(1<<b);k++){
				if(len[i]<L[j][k])continue;
				if(len[i]>L[j][k]+b-j)continue;
				if(len[i]>L[j][k]){
					int A=0;
					if(j&&(k&1)&&(str[i][L[j][k]]==str[i][L[j][k]-1]))A++;
					if(i&&(k&(1<<b-1))&&(str[i-1][len[i-1]-R[j][k]]==str[i][L[j][k]]))A++;
					dp[!u][(k*2+1)&mask]=max(dp[!u][(k*2+1)&mask],dp[u][k]+A);
				}
				if(len[i]<L[j][k]+b-j){
					dp[!u][(k*2)&mask]=max(dp[!u][(k*2)&mask],dp[u][k]);
				}
			}
			u=!u;
		}
	}
	int ret=0;
	for(int i=0;i<(1<<b);i++)
		ret=max(ret,dp[u][i]);
	printf("%d\n",ret*2);
}
/*
   INTERNATIONAL
C O LLEGIATE
PROGRAMMING
C O      NTEST
*/