CTFLAG - Flag

According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set:

  • In each row at most two different colours can be used.
  • No two adjacent squares can be painted the same colour.

Pay attention, please, that in one column more than two different colours can be used.

Berland's government took a decision to introduce changes into their country's flag in accordance with the new standard, at the same time they want these changes to be minimal. By the given description of Berland's flag you should find out the minimum amount of squares that need to be painted different colour to make the flag meet the new ISO standard. You are as well to build one of the possible variants of the new Berland's flag.

Input

The first input line contains 2 integers n and m (1 ≤ n, m ≤ 500) — number of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following n lines contains m characters. Each character is a letter from a to z, and it stands for the colour of the corresponding square.

Output

Output the minimum number of squares that need to be repainted to make the flag meet the new ISO standard.

Example

Input:
3 4
aaaa
bbbb
cccc

Output:
6

Added by:Phan Công Minh
Date:2010-06-21
Time limit:0.100s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Codeforces

hide comments
2016-04-22 17:45:32 anonymous
Note: You are only required to find the minimum number of squares that have to
be repainted, even though problem mentions that you have to build one of the
possible variants of the new Berland's flag.
2014-07-28 07:12:20 lite_coder
nyc problem...
2014-07-22 01:24:04 Jashan Goyal
Poorly managed for Python....
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.