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;

const int MAXC = 16;
const int MAXR = 200;
int R, C;
string S[MAXR];

int dp[2][1<<MAXC];

int main() {
  cin >> R >> C;
  for(int i = 0; i < R; ++i) {
    cin >> S[i];
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  int now = 0, next = 1;
  for(int i = 0; i < R; ++i) {
    for(int j = 0; j < C; ++j) {
      fill(dp[next], dp[next] + (1<<C), -1);
      for(int bit = 0; bit < (1<<C); ++bit) {
        if(dp[now][bit] == -1) continue;
        int value = dp[now][bit];

        char top = '_';
        if(i) {
          for(int k = C - j - 1, l = S[i-1].size(); k >= 0; --k) {
            if(bit >> k & 1) top = S[i-1][--l];
            else top = '_';
          }
        }

        char left = '_';
        int num = 0;
        for(int k = C - j, l = 0; k < C; ++k) {
          if(bit >> k & 1) left = S[i][l++], ++num;
          else left = '_';
        }

        do {
          int nbit = bit >> 1;
          if(num == S[i].size()) break;
          char c = S[i][num];
          nbit |= 1 << (C - 1);
          if(j+1 == C) {
            if(num+1 != S[i].size()) break;
          }
          dp[next][nbit] = max(dp[next][nbit],
                               value
                               + (isalpha(c) && c == top)
                               + (isalpha(c) && c == left));
        } while(0);

        do {
          int nbit = bit >> 1;
          if(j+1 == C) {
            if(num != S[i].size()) break;
          }
          dp[next][nbit] = max(dp[next][nbit], value);
        } while(0);
      }
      swap(now, next);
    }
  }
  int res = 0;
  for(int bit = 0; bit < (1<<C); ++bit) {
    res = max(res, dp[now][bit]);
  }
  cout << res*2 << endl;
  return 0;
}