Problem: Taro loves chocolate and when he returns from school he eats his favorite chocolate bar with a heart symbol on it. A recent pleasure is to eat all the heart symbol blocks to the end. Taro , Try to eat as many heartless blocks as possible, with all heartmark blocks connected.

<image>

However, Taro is still young, and even if he tries to eat as above, useless blocks will remain. Therefore, Taro seeks the maximum number of blocks that can be eaten when all the heart-shaped blocks are left connected. I asked you to create a program.

Taro can eat whatever way he wants, as long as all the heart-shaped blocks are connected. If one side of one block does not touch the other block, it will be separated.



Input

The input consists of multiple datasets, each dataset given in the following format:


H W
H x W numbers


H and W are integers indicating the vertical size and horizontal size of the chocolate bar, respectively. H x W numbers represent block information, '0' representing blocks without a heart mark, and blocks with a heart mark. Consists of '1'.

The end of the input is indicated by the dataset where H = W = 0. Do not output for this case.

You can assume that 1 ≤ H, W ≤ 12 and the number of heart-shaped blocks is 6 or less.

Output

For each dataset, output the maximum number of blocks that Taro can eat.

Example

Input

4 4
1 0 0 0
0 0 1 0
0 1 0 0
1 0 0 1
1 1
1
2 3
1 0 0
0 0 1
0 0


Output

7
0
2

Solution (in CPP):

Solution:
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef int cost_t;
const int INF = (int)(1.05e9);
const int MAX_W = 12;

int H, W;
const int dy[] = {1,-1,0,0}, dx[] = {0,0,1,-1};
int board[MAX_W][MAX_W];

int toIndex(int y, int x) {
	return y * W + x;
}

cost_t minimumSteiner(vector< vector<cost_t> > costMatrix, const vector<int> terminals) {
	const int n = costMatrix.size(), numTerminal = terminals.size();
	if (numTerminal <= 1) {
		return 0;
	}

	for (int k = 0; k < n; ++k) {
		costMatrix[k][k] = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				costMatrix[i][j] = min( costMatrix[i][j], costMatrix[i][k] + costMatrix[k][j] );
			}
		}
	}

	vector< vector<cost_t> > minCost(1<<numTerminal, vector<cost_t>(n, 0));

	for (int t = 0; t < numTerminal; ++t) {
		for (int v = 0; v < n; ++v) {
			minCost[1<<t][v] = costMatrix[terminals[t]][v];
		}
	}

	for (int occupiedBit = 1; occupiedBit < (1 << numTerminal); ++occupiedBit) if (occupiedBit & (occupiedBit - 1)) {
		for (int v = 0; v < n; ++v) {
			minCost[occupiedBit][v] = INF;
			for (int subMask = occupiedBit & (occupiedBit - 1); subMask > 0; subMask = (subMask - 1) & occupiedBit) {
				minCost[occupiedBit][v] = min( minCost[occupiedBit][v], minCost[subMask][v] + minCost[subMask ^ occupiedBit][v] );
			}
		}
		for (int v = 0; v < n; ++v) {
			for (int u = 0; u < n; ++u) {
				minCost[occupiedBit][v] = min( minCost[occupiedBit][v], minCost[occupiedBit][u] + costMatrix[u][v] );
			}
		}
	}

	return minCost[(1<<numTerminal) - 1][terminals[0]];
}

bool init() {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			scanf("%d", board[i] + j);
		}
	}

	return H > 0;
}

int solve() {
	vector< vector<int> > costMatrix(H*W, vector<int>(H*W, INF));
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			for (int k = 0; k < 4; ++k) {
				const int ny = y + dy[k], nx = x + dx[k];
				if ( 0 <= ny && ny < H && 0 <= nx && nx < W ) {
					costMatrix[toIndex(y, x)][toIndex(ny, nx)] = 1;
				}
			}
		}
	}

	vector<int> terminals;
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			if (board[y][x] == 1) {
				terminals.push_back(toIndex(y, x));
			}
		}
	}

	int minS = minimumSteiner(costMatrix, terminals);
	return H * W - (minS + 1);
}

int main() {
	for (; init(); ) {
		printf("%d\n", solve());
	}

	return 0;
}