Polycarp has a checkered sheet of paper of size _n_ × _m_. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
## Input
The first line contains two integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 100) — the sizes of the sheet.
The next _n_ lines contain _m_ letters '_B_' or '_W_' each — the description of initial cells' colors. If a letter is '_B_', then the corresponding cell is painted black, otherwise it is painted white.
## Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print _\-1_.
[samples]
## Note
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Polycarp 有一张大小为 $n × m$ 的方格纸。他将一些格子涂成了黑色,其余的仍然是白色。受 Malevich 的《黑方块》启发,Polycarp 希望涂最少数量的白色格子为黑色,使得所有黑色格子构成一个正方形。
你需要确定最少需要涂黑多少个格子,使得所有黑色格子构成一个边与纸张边缘平行的黑色正方形。不属于该正方形的所有格子必须为白色。正方形的边长必须为正数。
第一行包含两个整数 $n$ 和 $m$($1 ≤ n, m ≤ 100$)——纸张的尺寸。
接下来的 $n$ 行,每行包含 $m$ 个字母 '_B_' 或 '_W_',描述初始格子的颜色。如果字母是 '_B_',则对应格子为黑色;否则为白色。
请输出最少需要涂黑的格子数,使得黑色格子构成一个边与纸张边缘平行的黑色正方形,且所有不属于该正方形的格子均为白色。如果不可能,输出 _-1_。
在第一个例子中,需要涂黑 $5$ 个格子——$ (2, 2) $、$ (2, 3) $、$ (3, 2) $、$ (3, 3) $ 和 $ (4, 2) $。这样会形成一个边长为三的正方形,左上角位于 $ (2, 2) $。
在第二个例子中,所有格子均为黑色并构成一个矩形,因此无法得到一个正方形。
在第三个例子中,所有格子均为白色,因此只需将任意一个格子涂黑即可。
## Input
第一行包含两个整数 $n$ 和 $m$($1 ≤ n, m ≤ 100$)——纸张的尺寸。接下来的 $n$ 行,每行包含 $m$ 个字母 '_B_' 或 '_W_',描述初始格子的颜色。如果字母是 '_B_',则对应格子为黑色;否则为白色。
## Output
请输出最少需要涂黑的格子数,使得黑色格子构成一个边与纸张边缘平行的黑色正方形,且所有不属于该正方形的格子均为白色。如果不可能,输出 _-1_。
[samples]
## Note
在第一个例子中,需要涂黑 $5$ 个格子——$ (2, 2) $、$ (2, 3) $、$ (3, 2) $、$ (3, 3) $ 和 $ (4, 2) $。这样会形成一个边长为三的正方形,左上角位于 $ (2, 2) $。在第二个例子中,所有格子均为黑色并构成一个矩形,因此无法得到一个正方形。在第三个例子中,所有格子均为白色,因此只需将任意一个格子涂黑即可。
**Definitions**
Let $ n, m \in \mathbb{Z}^+ $ be the dimensions of the grid, with $ 1 \leq n, m \leq 100 $.
Let $ G \in \{B, W\}^{n \times m} $ be the initial grid, where $ G[i][j] $ denotes the color of cell at row $ i $, column $ j $.
**Constraints**
1. A valid solution requires a square $ S \subseteq G $ of side length $ s \in \mathbb{Z}^+ $, with sides parallel to the grid axes.
2. All cells in $ S $ must be black.
3. All cells not in $ S $ must be white.
4. The square must contain at least one black cell from the original grid (otherwise, if all cells are white, we may paint one cell, but if there are black cells outside any possible square, it's impossible).
**Objective**
Find the minimum number of white cells to repaint black such that:
- There exists a square $ S $ of side $ s \geq 1 $, with top-left corner at $ (r, c) $, where $ 1 \leq r \leq n - s + 1 $, $ 1 \leq c \leq m - s + 1 $,
- $ G[i][j] = B $ for all $ (i,j) \in S $ after repainting,
- $ G[i][j] = W $ for all $ (i,j) \notin S $,
- The number of repainted cells is minimized.
If no such square exists (i.e., black cells cannot be confined to any square without violating the "all non-square cells white" condition), output $-1$.
Let $ \text{cost}(r, c, s) = $ number of white cells in the square $ S $ at $ (r,c) $ with side $ s $ that need to be painted black, **plus** the number of black cells outside $ S $ that must be painted white — but since we are only allowed to paint white cells black (not repaint black to white), **any configuration where a black cell lies outside the chosen square is invalid**.
Thus, the problem reduces to:
For each possible square $ S $ of side $ s \geq 1 $ and top-left corner $ (r, c) $:
- If there exists any $ (i,j) \in S $ such that $ G[i][j] = W $, then we must paint it black → cost increases by 1.
- If there exists any $ (i,j) \notin S $ such that $ G[i][j] = B $, then this configuration is **invalid** (we cannot remove black cells).
So, for each square candidate $ S $:
- If all black cells in $ G $ are contained within $ S $, then the cost is $ s^2 - \text{number of black cells already in } S $.
- Otherwise, skip this square.
**Objective**:
$$
\min_{\substack{1 \leq s \leq \min(n,m) \\ 1 \leq r \leq n - s + 1 \\ 1 \leq c \leq m - s + 1}} \left\{ s^2 - \sum_{i=r}^{r+s-1} \sum_{j=c}^{c+s-1} \mathbf{1}_{G[i][j] = B} \right\}
$$
subject to:
$$
\forall (i,j) \in \{1,\dots,n\} \times \{1,\dots,m\} \setminus ([r, r+s-1] \times [c, c+s-1]), \quad G[i][j] = W
$$
If no such square exists, output $-1$.