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 rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int H,W,dp[2][1<<16],I;
string s[128];
bool B(int x,int i){return (x>>i)&1;}
int bc(int x){return x==0?0:__builtin_popcount(x);}
int main(){
	cin>>H>>W;
	rep(i,H) cin>>s[i];
	rep(b,1<<W) dp[0][b]=-1;
	dp[0][0]=0;
	rep(i,H){
		rep(j,W){
			rep(b,1<<W) dp[1-I][b]=-1;
			rep(b,1<<W){
				if(dp[I][b]<0) continue;
				//put
				int x=bc(b&((1<<j)-1));
				if(x<s[i].size()){
					int pl=0;
					if(i>0&&B(b,j)&&s[i-1][s[i-1].size()+x-bc(b)]==s[i][x]) pl+=2;//tate
					if(j>0&&B(b,j-1)&&s[i][x]==s[i][x-1]) pl+=2;//yoko
					chmax(dp[1-I][b|(1<<j)],dp[I][b]+pl);
				}
				//dont put
				chmax(dp[1-I][b&(~(1<<j))],dp[I][b]);
			}
			I=1-I;
		}
		rep(b,1<<W) if(bc(b)!=s[i].size()) dp[I][b]=-1;
	}
	int ans=0;
	rep(i,1<<W) chmax(ans,dp[I][i]);
	cout<<ans<<endl;
}