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;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int dp[2][1<<16];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int R, C;
  cin >> R >> C;
  VI len(R);
  VS vs(R);
  REP(i,R){
	cin >> vs[i];
	len[i] = SZ(vs[i]);
  }

  int crt = 0, nxt = 1;
  fill((int*)dp, (int*)dp+2*(1<<16), -1);
  REP(B,1<<C){
	if(__builtin_popcount(B) != len[0]) continue;
	dp[crt][B] = 0;
	for(int x=0,i=0;i+1<len[0];++i){
	  while(x < C && (B>>x&1) == 0) ++x;
	  if((B>>(x+1)&1) && vs[0][i] == vs[0][i+1])
		dp[crt][B]++;
	  ++x;
	}
  }

  FOR(y,1,R){
	REP(x,C){
	  fill(dp[nxt], dp[nxt]+(1<<16), -1);
	  REP(B,1<<C) if(dp[crt][B] >= 0){
		// not place character
		maxi(dp[nxt][B>>1], dp[crt][B]);

		int next_b = (B >> 1) | (1 << (C-1));
		int next = dp[crt][B];
		int lb = B & ((1<<(C-x))-1);
		int lbi = len[y-1] - __builtin_popcount(lb);
		int ub = B >> (C-x);
		int ubi = __builtin_popcount(ub);

		if(ubi >= len[y])
		  continue;
		// up
		if(lbi < len[y-1] && (B&1) && vs[y-1][lbi] == vs[y][ubi])
		  ++next;
		// left
		if(ubi > 0 && (B>>(C-1)&1) && vs[y][ubi-1] == vs[y][ubi])
		  ++next;

		maxi(dp[nxt][next_b], next);
	  }
	  swap(crt, nxt);
	}

	REP(B,1<<C){
	  if(__builtin_popcount(B) != len[y])
		dp[crt][B] = -1;
	}
  }

  int ans = 0;
  REP(B,1<<C)
	maxi(ans, dp[crt][B]);
  cout << ans*2 << endl;

  return 0;
}