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;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int dp[2][1 << 16],*now = dp[0],*nxt = dp[1];
	int h,w;
	string s[130];
	cin >> h >> w;
	for(int i = 0;i < h;i++) cin >> s[i];
	for(int i = 0;i < (1 << w);i++) now[i] = nxt[i] = -INF;
	now[0] = 0;
	int popcount[1 << 16];
	for(int i = 0;i < (1 << w);i++) popcount[i] = __builtin_popcountll(i);
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			for(int k = 0;k < (1 << w);k++) nxt[k] = -INF;
			for(int k = 0;k < (1 << w);k++){
				int l = popcount[k % (1 << j)];
				if(now[k] < 0) continue;
				int up = s[i-1].length()-popcount[k >> j];
				int add = (((k>>j)&1) && i && s[i-1][up]==s[i][l])
				+ (l && ((k>>(j-1))&1) && s[i][l-1]==s[i][l]);
				chmax(nxt[k | (1 << j)],now[k] + 2 * add);
				chmax(nxt[k & ~(1 << j)],now[k]);
			}
			swap(now,nxt);
		}
		for(int k = 0;k < (1 << w);k++){
			if(popcount[k] != s[i].length()) now[k] = -INF;
		}
	}
	int ans = -INF;
	for(int i = 0;i < (1 << w);i++) chmax(ans,now[i]);
	cout << ans << endl;
}