Connect#5838

Connect

5 seconds
64 megabytes
Very hard

You are playing a solitaire puzzle called "Connect", which uses several letter tiles.

There are R \times C empty cells. For each (1 \le i \le R), you must put a string s_i (1 \le |s_i| \le C) in the -th row of the table, without changing the letter order. In other words, you choose an integer sequence a_j such that 1 \le a_1 < a_2 < \ldots < a_{|s_i|} \le C, and put the -th character of the string s_i in the a_j-th column (1 \le j \le |s_i|).

For example, when C = 8 and s_i = "ICPC", you can put s_i like followings.

I_C_P_C_

ICPC____

_IC___PC

'_' represents an empty cell.

For each non-empty cell , you get a point equal to the number of adjacent cells which have the same character as . Two cells are adjacent if they share an edge.

Calculate the maximum total points you can get.

Input

The first line contains two integers and (1 \le R \le 128, 1 \le C \le 16).

Then lines follow, each of which contains s_i (1 \le |s_i| \le C). All characters of s_i are uppercase letters.

Output

Output the maximum total points in a line.

Examples

Example 1

Loading
Loading