Monsters

Given a binary N x M grid, choose one intact cell to destroy so that the number of all-1 submatrices remaining is minimized, and report that minimum count.

Hard8ArrayDynamic programmingBrute forcePrefix sumNo attempts yetTime limit1sMemory limit32 MB

Problem

Humans have landed on a planet of the Centaurus constellation, and the planet is inhabited by monsters. The monsters' defense system is made of battle cells arranged as a matrix with NN rows and MM columns.

Our army has already destroyed some of the cells. Now it is your turn, and you destroy exactly one intact cell of your choice.

The strength of the defense system is the number of submatrices that contain only intact cells. Submatrices that overlap each other are counted separately. A submatrix is a nonempty matrix obtained from the original matrix by removing:

  • some consecutive rows, starting from the first one,
  • some consecutive rows, ending at the last one,
  • some consecutive columns, starting from the first one,
  • some consecutive columns, ending at the last one.

Pick the cell to destroy so that the strength of the defense system becomes as small as possible, and compute the strength after your attack.

Input

The first line contains two integers NN and MM separated by a space, the number of rows and the number of columns (1N,M3001 \le N, M \le 300).

Each of the next NN lines contains a binary string of length MM describing the cells of the matrix. A 1 is an intact cell, and a 0 is a cell our army already destroyed.

At least one cell is intact.

Output

Print the strength of the defense system after your attack on a single line.

Constraints

  • 1N,M3001 \le N, M \le 300
  • Every line of the matrix consists of the characters 0 and 1 only.
  • At least one cell is intact.