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 <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PInt;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int dp[2][1<<16];
int main() {
  int R, C;
  cin >> R >> C;
  string A[130];
  rep(i, R) cin >> A[i];
  int cur = 0, next = 1;
  memset(dp, -1, sizeof(dp));
  dp[cur][0] = 0;
  rep(i, R) rep(j, C) {
    //    rep(k, 1<<C) dp[next][k] = 0;
    memset(dp + next, -1, sizeof(dp[0]));
    rep(k, 1<<C) if (dp[cur][k] != -1) {
      int score = 0;
      int ak = k & ~(1<<j);
      dp[next][ak] = max(dp[next][ak], dp[cur][k] + score);

      char c = A[i][__builtin_popcount(k&((1<<j)-1))];
      if (i > 0 && (k>>j&1) && (A[i-1][SZ(A[i-1]) - __builtin_popcount(k>>j)] == c)) score++;
      if (j > 0 && (k>>(j-1)&1) && (A[i][__builtin_popcount(k&((1<<j)-1))-1] == c)) score++;
      ak = k | 1<<j;
      dp[next][ak] = max(dp[next][ak], dp[cur][k] + score);
    }
    swap(cur, next);
    if (j+1 == C) {
      rep(k, 1<<C) if (__builtin_popcount(k) != SZ(A[i])) dp[cur][k] = -1;
    }
  }

  int ans = 0;
  rep(k, 1<<C)
    ans = max(ans, dp[cur][k]);
  cout << ans * 2 << endl;


}