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 int long long
#define all(v) (v).begin(), (v).end()
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int R, C;
string s[202];

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

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> R >> C;
  rep(i, R) cin >> s[i];

  memset(dp, -1, sizeof(dp));

  int *cur = dp[0], *next = dp[1];
  cur[0] = 0;
  rep(i, R) rep(j, C) {
    rep(bit, 1<<16) next[bit] = -1;
    rep(bit, 1<<C) {
      if(cur[bit] == -1) continue;
      //rep(bit, C) cout<<(int)(bit&(1<<C));
      //cout<<endl;

      int idx = __builtin_popcountll(bit&((1<<j)-1));
      //cout<<idx<<" "<<j<<" "<<C<<endl;

      if(idx+C-j > (int)s[i].size()) { // empty
	chmax(next[bit&~(1<<j)], cur[bit]);
      }

      if(idx < (int)s[i].size()) { // char
	//cout<<s[i]<<endl;
	int same = 0;
	if(j > 0 && ((bit>>(j-1))&1)) { // left
	  if(idx > 0 && s[i][idx] == s[i][idx-1]) same += 2;
	}

	if(i > 0 && ((bit>>j)&1)) { // above
	  int sz = s[i-1].size();
	  int above = __builtin_popcountll(bit>>j);
	  //cout<<sz<<" "<<above<<endl;
	  //cout<<s[i-1]<<endl;
	  if(sz >= above && s[i][idx] == s[i-1][sz-above]) same += 2;
	}

	//cout<<same<<endl;
	chmax(next[bit|1<<j], cur[bit]+same);
      }
    }
    swap(cur, next);
  }

  int ans = 0;
  rep(bit, 1<<C) chmax(ans, cur[bit]);
  cout << ans << endl;

  return 0;
}