#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int BEET=-1001001001;

int H,W;
string S[222];

int dp[2][1<<16];
int pc[1<<16];
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);

    for(int i=0;i<1<<16;i++)pc[i]=__builtin_popcount(i);
    cin>>H>>W;
    S[0]="";
    rep(i,H)cin>>S[i+1];

    fill_n(*dp,2*(1<<16),BEET);
    dp[0][0]=0;
    int mask=(1<<W)-1;
    for(int t=0;t<H*W;t++){
            const int i=t/W,j=t%W,p=t&1,q=(t+1)&1;
            const int beet=(1<<(W-1));
            const int ei=(1<<W);
            const int mask2=(1<<j)-1;
            const int len=S[i].size();
            const int len2=S[i+1].size();

            for(int k=0;k<beet;k++){
                if(dp[p][k]==BEET)continue;
                chmax(dp[q][(k<<1)&mask],dp[p][k]);

                int l=pc[k&mask2];
                if(l<len2){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    chmax(dp[q][((k<<1)&mask)+1],dp[p][k]+po*2);
                }
                dp[p][k]=BEET;
            }

            for(int k=beet;k<ei;k++){
                if(dp[p][k]==BEET)continue;
                chmax(dp[q][(k<<1)&mask],dp[p][k]);

                int l=pc[k&mask2];
                if(l<len2){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    if(S[i][len-pc[k]+l]==S[i+1][l])po++;
                    chmax(dp[q][((k<<1)&mask)+1],dp[p][k]+po*2);
                }
                dp[p][k]=BEET;
            }

        if(j==W-1)for(int k=0;k<ei;k++)if(pc[k]!=len2)dp[q][k]=BEET;
    }

    int ans=BEET;
    rep(i,1<<W)chmax(ans,dp[(H*W)&1][i]);
    cout<<ans<<endl;
    return 0;
}