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<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;


void solve() {
	int h, w; cin >> h >> w;
	vector<int> dp(1 << w,-mod);
	vector<int> cop(1 << w);
	int sup = (1 << w);
	dp[0] = 0;
	vector<string> s(h);
	rep(i, h)cin >> s[i];
	rep(i, h) {
		int len = s[i].length();
		rep(j, w) {
			fill(cop.begin(), cop.end(), -mod);
			rep(k, sup) {
				if (dp[k] < 0)continue;
				//take
				int tmp = 0;
				vector<bool> b;
				rep(l, w) {
					if (k&(1 << l))b.push_back(true);
					else b.push_back(false);
				}
				rep(l, j)if (b[l])tmp++;
				int tmpall = 0;
				rep(l, w)if (b[l])tmpall++;
				if (tmp < len) {
					int nid = k * 2+1; nid %= sup;
					int val = dp[k];
					if (b[0] && j > 0) {
						if (s[i][tmp - 1] == s[i][tmp])val++;
					}
					if (b[w - 1]) {
						if (s[i - 1][(int)s[i - 1].length() - (tmpall - tmp)] == s[i][tmp])val++;
					}
					cop[nid] = max(cop[nid], val);
				}
				//non_take
				int nid = k * 2; nid %= sup;
				cop[nid] = max(cop[nid], dp[k]);
			}
			rep(k, sup) {
				bool f = true;
				int tmp = 0;
				rep(l, j + 1) {
					if (k&(1 << l))tmp++;
				}
				if (tmp + w - (j + 1) < len)f=false;
				if (f) {
					dp[k] = cop[k];
				}
				else {
					dp[k] = -mod;
				}

			}
		}
	}
	int ans = 0;
	rep(i, (1 << w))ans = max(ans, dp[i]);
	cout << ans*2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	//cout << fixed << setprecision(10);
	//init();
	/*while (cin >> m >> num[0] >> num[1], m | num[0] | num[1]) {
		solve();
	}*/
	solve();
	//stop
	return 0;
}