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:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dpc[1 << 16], dpn[1 << 16];

signed main() {
    int R, C; cin >> R >> C;
    fill(dpc, dpc + (1<<C), -1);
    fill(dpn, dpn + (1<<C), -1);
    dpc[0] = 0;
    int pn = 0;
    string ps = "";
    for(int i=0; i<R; i++) {
        string s; cin >> s;
        int N = s.length();
        for(int j=0; j<C; j++) {
            for(int bit=0; bit<(1<<C); bit++) {
                if(dpc[bit] < 0) continue;
                // fprintf(stderr, "i = %lld, j = %lld, bit = %lld, dp = %lld\n", i, j, bit, dpc[bit]);
                {
                    int mask1 = (1 << j) - 1;
                    int mask2 = (1 << C) - 1 - mask1;
                    // 置く (j 列目に k 文字目を置く)
                    int k = __builtin_popcount(bit & mask1);
                    int l = pn - __builtin_popcount(bit & mask2);
                    
                    if(k < N) {
                        int c1 = (k > 0 and j > 0 and (bit >> (j-1) & 1) and s[k-1] == s[k]);
                        int c2 = (i > 0 and bit >> j & 1) and (ps[l] == s[k]);

                        int nbit = bit | (1 << j);
                        chmax(dpn[nbit], dpc[bit] + (c1 + c2) * 2);
                    }
                }

                {
                    // 置かない
                    int mask1 = (1 << j) - 1;
                    int k =__builtin_popcount(bit & mask1);
                    // 残りマス数
                    int remA = C - j - 1, remB = N - k;
                    if(remA >= remB) {
                        int nbit = bit;
                        if(nbit >> j & 1) nbit -= (1 << j);
                        chmax(dpn[nbit], dpc[bit]);
                    }
                }
                dpc[bit] = -1;
            }
            swap(dpn, dpc);
        }
        pn = N; ps = s;
    }
    int ans = *max_element(dpc, dpc + (1<<C));
    cout << ans << endl;
    return 0;
}