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 <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char word[128][17],pre[17],now[17];
int POW[17];
int length[128],dp[2][1<<17];
int num_bit[1<<17];

int main(){

	for(int i = 0; i < 17; i++)POW[i] = pow(2,i);

	int H,W;
	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		scanf("%s",word[row]);
		for(length[row] = 0; word[row][length[row]] != '\0'; length[row]++);
	}

	int CURRENT = 0,NEXT = 1;

	for(int state = 0; state < POW[W]; state++){
		num_bit[state] = __builtin_popcount(state);
		dp[CURRENT][state] = -1;
		dp[NEXT][state] = -1;
	}

	dp[CURRENT][0] = 0;
	int loc,next;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			for(int state = 0; state < POW[W]; state++)dp[NEXT][state] = -1;

			for(int state = 0; state < POW[W]; state++){

				if(dp[CURRENT][state] == -1)continue;

				loc = num_bit[state & (1 << col)-1];

				if(loc < length[row]){
					next = dp[CURRENT][state];

					if(col > 0 && (state & (1 << (col-1))) != 0 && word[row][loc-1] == word[row][loc])next++;

					if(row > 0 && (state & 1 << col) != 0 && word[row][loc] == word[row-1][length[row-1]-num_bit[state >> col]])next++;
					dp[NEXT][state|1 << col] = max(dp[NEXT][state|1 << col],next);
				}

				if(loc+W-col > length[row]){
					dp[NEXT][state & ~(1 << col)] = max(dp[NEXT][state & ~(1 << col)], dp[CURRENT][state]);
				}
			}
			swap(CURRENT,NEXT);
		}
	}

	int ans = 0;
	for(int state = 0; state < POW[W]; state++){
		ans = max(ans,dp[CURRENT][state]);
	}

	printf("%d\n",2*ans);

	return 0;
}