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;

int main()
{
  int R, C;
  string S[128];
  int hash[1 << 16];
  for(int i = 0; i < 1 << 16; i++) hash[i] = __builtin_popcount(i);

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

  int dp1[1 << 16], dp2[1 << 16];
  memset(dp1, -1, sizeof(dp1));
  int *latte = dp1, *malta = dp2;
  latte[0] = 0;
  for(int y = 0; y < R; y++) {
    for(int x = 0; x < C; x++) {
      for(int j = 0; j < 1 << C; j++) malta[j] = -1;
      for(int j = 0; j < 1 << C; j++) {
        if(latte[j] == -1) continue;

        auto ch = [&](int &a, int b)
        {
          a = max(a, b);
        };

        const int beet = hash[j & ((1 << x) - 1)];
        if(beet + C - x > S[y].size()) {
          ch(malta[j & ~(1 << x)], latte[j]);
        }
        if(beet < S[y].size()) {
          int point = 0;
          if(x && (j >> (x - 1)) & 1) {
            if(beet && S[y][beet] == S[y][beet - 1]) ++point;
          }
          if(y && (j >> x) & 1) {
            int pos = (int) S[y - 1].size() - hash[j >> x];
            if(pos >= 0 && S[y - 1][pos] == S[y][beet]) ++point;
          }
          ch(malta[j | (1 << x)], latte[j] + point);
        }
      }
      swap(latte, malta);
    }
  }
  cout << *max_element(begin(dp1), end(dp1)) * 2 << endl;
}