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:
/*
https://suikaba.hatenablog.com/entry/2017/09/28/182203
十分に高速化を考えないとTLE
*/
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int R, C;
    cin>>R>>C;
    vector<string>s(R);
    for(int i=0;i<R;i++)cin>>s[i];
    vector<int>bitcount(1<<C);
    for(int i=0;i<(1<<C);i++)bitcount[i]=__builtin_popcount(i);
    vector<int>dp(1<<C, -1);
    dp[0] = 0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            vector<int>nxt(1<<C, -1);
            for(int S=0;S<(1<<C);S++){
                if(dp[S]==-1)continue;
                int idx = bitcount[S & (1<<j) - 1];
                if(idx < s[i].size()){
                    int t = dp[S];
                    if(idx > 0 && (S & 1 << (j - 1)) && s[i][idx - 1] == s[i][idx]) {
                        t++;
                    }
                    if(i > 0 && (S & 1 << j) && s[i][idx] == s[i - 1][s[i - 1].size() - bitcount[S >> j]]) {
                        t++;
                    }
                    nxt[S | 1 << j] = max(nxt[S | 1 << j], t);
                }
                if(C - j > s[i].size() - idx) {
                    nxt[S & ~(1 << j)] = max(nxt[S & ~(1 << j)], dp[S]);
                }
            }
            dp.swap(nxt);
        }
    }
    int ans = 0;
    for(int i=0;i<dp.size();i++)ans=max(ans, dp[i]);
    cout<<ans*2<<endl;
    return 0;
}