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 <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <valarray>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <sstream>
using namespace std;
 
#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-9;
 
int dp[2][1<<16];
int r,c;
string input[128];
 
int main() {
  cin>>r>>c;
  for(int i=0; i<r; ++i) cin>>input[i];
 
  memset(dp,-1,sizeof(dp));
 
  int *cur = dp[0];
  int *nxt = dp[1];
 
  cur[0] = 0;
  REP(i,r) {
    REP(j,c) {
      REP(S,1<<c) nxt[S] = -1;
      REP(S,1<<c) {
        if (cur[S] == -1) continue;
 
        int S1 = S & ((1<<j)-1);
        int S2 = S ^ S1;
        int n1 = __builtin_popcount(S1);
        int n2 = __builtin_popcount(S2);
        char left = '_';
        if (j&&n1) {
          if (S>>(j-1)&1) {
            left = input[i][n1-1];
          }
        }
        char up = '_';
        if (i>0 && n2) {
          if ((S>>j)&1) {
            up = input[i-1][input[i-1].size()-n2];
          }
        }
        // cout << bitset<3>(S) << " " << bitset<3>(S1) << " "<< bitset<3>(S2) << endl;
        // printf("(%d,%d) %d %c %c\n", i,j, cur[S],left,up);
        // bit たてる
        if (n1 < input[i].size()) {
          char now = input[i][n1];
          int score = 0;
          if (now == left) score+=2;
          if (now == up) score+=2;
          int T = S|1<<j;
          // if (score) {
          //   printf("(%d,%d) %d %c %c %c\n", i,j, cur[S],left,up, now);
          // }
          nxt[T] = max(nxt[T], cur[S]+score);
        }
        int len = input[i].size();
        if (len-n1 <= c-j-1) {
          // たてない
          int T = S & (~(1<<j));
          nxt[T] = max(nxt[T], cur[S]);
        }
      }
      swap(cur, nxt);
    }
  }
  int ans = 0;
  REP(S,1<<c) {
    // if (cur[S] == 18) {
    //   cout <<bitset<16>(S) << endl;
    // }
    ans = max(ans, cur[S]);
  }
 
  cout << ans << endl;
}