Harps and Tails

Flip any subset of columns of an H/T grid; find the maximum number of rows that can be made all-H.

Medium4Hash mapGreedyBit manipulationImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Gary likes the Celtic harp on the 1 euro coin. He has a grid of such coins with nn rows and mm columns. Each coin lies with either the harp or the tail facing up.

Gary wants as many rows as possible to show a harp in every cell. He is allowed one operation: choose a column and turn over every coin in that column. A coin that showed the harp then shows the tail, and a coin that showed the tail then shows the harp.

Gary may repeat the operation as many times as he likes. Find the largest number of rows that show a harp in every cell once he stops.

Input

The first line contains the number of rows nn and the number of columns mm, separated by a space (1n,m10001 \le n, m \le 1000).

Each of the next nn lines contains a string of length mm describing one row of the grid. The jj-th character of the ii-th line is 'T' if the coin in row ii, column jj shows a tail, and 'H' if it shows the harp.

Output

Print one line with the largest possible number of rows that show a harp in every cell.