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 <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

int main(){
    int H, W;
    while(cin >> H >> W){
        vector<string> str(H);
        REP(i, H) cin >> str[i];

        const int MAXS = 1 << W;
        vector<int> dp(MAXS, -INF);
        dp[0] = 0;
        for(int y = 0; y < H; y++){
            for(int x = 0; x < W; x++){
                vector<int> next(MAXS, -INF);
                for(int s = 0; s < MAXS; s++) if(dp[s] >= 0){
                    int cu = __builtin_popcount(s >> x); // count of upper
                    int cl = __builtin_popcount(s & ((1 << x) - 1)); // count of lower
                    assert(cu + cl == __builtin_popcount(s));

                    if(cl + (W - 1 - x) >= str[y].size())
                        next[s << 1 & (MAXS - 1)] = max(next[s << 1 & (MAXS - 1)], dp[s]); // path through

                    if(cl == str[y].size()) continue;

                    int add = 0;
                    if(cl > 0 && str[y][cl] == str[y][cl - 1] && (s & 1)){
                        add += 2;
                    }
                    if(y > 0 && (s >> (W - 1) & 1) && str[y - 1][str[y - 1].size() - cu] == str[y][cl]){
                        add += 2;
                    }
                    next[(s << 1 & (MAXS - 1)) | 1] = max(next[(s << 1 & (MAXS - 1)) | 1], dp[s] + add);
                }
                dp.swap(next);
            }
        }
        int ans = 0;
        for(int s = 0; s < MAXS; s++) ans = max(ans, dp[s]);
        cout << ans << endl;
    }
    return 0;
}