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<cstdio>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char s[128][17];
	int len[128];
	rep(i,h) scanf("%s",s[i]), len[i]=strlen(s[i]);

	static int pc[1<<16];
	rep(S,1<<w) pc[S]=popcount(S);

	static int dp[2][16][1<<16];
	rep(i,2) rep(j,w) rep(S,1<<w) dp[i][j][S]=-INF;
	dp[1][w-1][0]=0;
	rep(i,h){
		int y=i%2;
		rep(j,w){
			// i 行目の 0~j-1 列目に k 文字置いた
			for(int k=max(len[i]-(w-j),0);k<=min(len[i],j);k++){
				// j 個から k 個選ぶ組み合わせ
				for(int S1=(1<<k)-1,_,__;S1<(1<<j);_=S1&-S1,__=S1+_,S1=((S1&~__)/_>>1)|__){
					// i-1 行目の j~w-1 列目に l 文字置いた
					for(int l=max((i>0?len[i-1]:0)-j,0);l<=min(w-j,(i>0?len[i-1]:w));l++){
						// w-j 個から l 個選ぶ組み合わせ
						for(int S2=(1<<l)-1,_,__;S2<(1<<w-j);_=S2&-S2,__=S2+_,S2=((S2&~__)/_>>1)|__){
							int S=S1|S2<<j;

							if(j>0){
								// s[i][k] を置かない
								dp[y][j][S&~(1<<j)]=max(dp[y][j][S&~(1<<j)],dp[y][j-1][S]);
								// s[i][k] を置く
								int plus=0;
								if(k>0 && s[i][k-1]==s[i][k] && S&1<<j-1) plus++; // 左と隣接
								if(i>0 && s[i][k]==s[i-1][len[i-1]-pc[S2]] && S&1<<j) plus++; // 上と隣接
								dp[y][j][S|(1<<j)]=max(dp[y][j][S|(1<<j)],dp[y][j-1][S]+plus);
							}
							else{ // j==0
								// s[i][k] を置かない
								dp[y][j][S&~(1<<j)]=max(dp[y][j][S&~(1<<j)],dp[1-y][w-1][S]);
								// s[i][k] を置く
								int plus=0;
								if(i>0 && s[i][k]==s[i-1][len[i-1]-pc[S2]] && S&1<<j) plus++; // 上と隣接
								dp[y][j][S|(1<<j)]=max(dp[y][j][S|(1<<j)],dp[1-y][w-1][S]+plus);
							}

							if(S2==0) break;
						}
					}

					if(S1==0) break;
				}
			}
		}
	}

	int ans=0;
	rep(S,1<<w) ans=max(ans,2*dp[(h-1)%2][w-1][S]);
	printf("%d\n",ans);

	return 0;
}