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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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, -1);
    dp[0] = 0;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            vector<int> next(1<<w, -1);
            for(int i=0; i<(1<<w); ++i){
                if(dp[i] == -1)
                    continue;

                bitset<32> bs(i);
                int a = (bs & bitset<32>((1 << x) - 1)).count();
                int b = (bs >> x).count();

                if(a + w - x - 1 >= s[y].size()){
                    bitset<32> bs2 = bs << 1;
                    bs2[w] = false;
                    next[bs2.to_ulong()] = max(next[bs2.to_ulong()], dp[i]);
                }

                if(a < s[y].size()){
                    int p = dp[i];
                    if(bs[w-1] && s[y-1][s[y-1].size()-b] == s[y][a])
                        p += 2;
                    if(a > 0 && bs[0] && s[y][a-1] == s[y][a])
                        p += 2;

                    bitset<32> bs2 = bs << 1;
                    bs2[w] = false;
                    bs2[0] = true;
                    next[bs2.to_ulong()] = max(next[bs2.to_ulong()], p);
                }
            }
            dp.swap(next);
        }
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;
}