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 <vector>
#include <algorithm>
#include <map>
using namespace std;

int popcount(int n){
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    return (n & 0x0000ffff) + (n >>16 & 0x0000ffff);
}

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    vector<int> dp(1<<w, 0);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            vector<int> ndp(1<<w, 0);
            for(int bits=0; bits<(1<<w); bits++){
                int pop_total = popcount(bits);
                int pop_prevline = popcount(bits>>j);
                int pop_currline = pop_total -pop_prevline;
                if(i==0 and pop_prevline>0) continue;
                if(i>0 and pop_prevline>(int)s[i-1].length()) continue;
                if(i>0 and j+pop_prevline<(int)s[i-1].length()) continue;
                if(pop_currline > (int)s[i].length()) continue;
                if(i==3 and j==0 and bits==53191){
                }
                // 空白
                if(w-j-1+pop_currline >= (int)s[i].length()){
                    int &next = ndp[bits&~(1<<j)];
                    next = max(next, dp[bits]);
                }
                // 置く
                if(pop_currline+1 <= (int)s[i].length()){
                    int score = 0;
                    char self = s[i][pop_currline];
                    if(i>0 and (bits>>j&1) and self==s[i-1][(int)s[i-1].length()-pop_prevline]){
                        score += 2;
                    }
                    if(j>0 and (bits>>(j-1)&1) and self==s[i][pop_currline-1]){
                        score += 2;
                    }
                    int &next = ndp[bits|(1<<j)];
                    next = max(next, dp[bits]+score);
                }
            }
            swap(dp, ndp);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}