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;

typedef pair<int,int> P;

int R,C;
string S[129];
int dp[2][(1<<16)];

int getcost(int x,int y,int bt,int txc,int tyc){
  int ret = 0;
  if( bt&1 ) {
    if( (int)S[y].size() <= txc ) return -100000000;
    if(y>0){
      if( (bt & (1<<C)) ){
        int ind = (int)S[y-1].size() - tyc;
        if( S[y][txc] == S[y-1][ind] ) {
          ret += 2;
        }
      }
    }
    if(txc>0 && (bt&2) ){
      if( S[y][txc] == S[y][txc-1] ) {
        ret += 2;
      }
    }
  }

  //  cout << x << " "<< y << " "<< txc<< " " <<tyc <<" "<< endl;
  //cout << bitset<17>(bt) << endl;
  //cout << ret << endl;
  return ret; 
}

int main(){
  cin >> R >> C;
  for(int i=0;i<R;i++) cin >> S[i];

  memset(dp,-1,sizeof(dp));
  dp[0][0] = 0;
  for(int y=0;y<R;y++){
    int size = (int)S[y].size();
    for(int x=0;x<C;x++){
      int now = (C*y+x)&1;
      int nex = 1-now;
      memset(dp[nex],-1,sizeof(dp[nex]));
      for(int i=0;i<(1<<C);i++){
        int nc = dp[now][i];
        if(nc < 0 ) continue;
        int prx = (i & ((1<<x)-1) );
        int pry = (i & (~((1<<x)-1)) );
        int txc = __builtin_popcount(prx);
        int tyc = __builtin_popcount(pry);
        if( txc > size ) continue;
        if( y>0 &&  x==0 && (int)S[y-1].size() != tyc ) continue;
        if( y>0 && (int)S[y-1].size() - tyc < 0 ) continue;
        int nbt = (i<<1);
        nbt &= ((1<<C)-1);
        if( x - txc < C-size )
          dp[nex][nbt] = max( dp[nex][nbt], nc );
        int nxc = getcost(x,y,(i<<1)|1,txc,tyc);
        dp[nex][nbt|1] = max( dp[nex][nbt|1], nc + nxc );
      }
    }
  }

  int res = 0;
  for(int i=0;i<(1<<C);i++){
    int now = (C*R)&1;
    int tyc = __builtin_popcount(i);
    if((int)S[R-1].size() != tyc ) continue;
    res = max( res, dp[now][i] );
 }
  cout << res << endl;

}