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 <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

const int INFTY=1<<29;

int main()
{
	for(int h,w;cin>>h>>w,h|w;){
		int n=h*w;
		vvi dist(n,vi(n,INFTY));
		vi hearts;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				int x; cin>>x;
				if(x==1)
					hearts.push_back(i*w+j);
				
				dist[i*w+j][i*w+j]=0;
				int di[]={-1,1,0,0},dj[]={0,0,-1,1};
				for(int k=0;k<4;k++){
					int ii=i+di[k],jj=j+dj[k];
					if(0<=ii && ii<h && 0<=jj && jj<w)
						dist[i*w+j][ii*w+jj]=dist[ii*w+jj][i*w+j]=1;
				}
			}
		}
		
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		
		int hsize=hearts.size();
		vvi dp(1<<hsize,vi(n,INFTY));
		for(int i=0;i<hsize;i++)
			for(int j=0;j<n;j++)
				dp[1<<i][j]=dist[hearts[i]][j];
		
		for(int i=0;i<(1<<hsize);i++){
			for(int j=i;j;j=(j-1)&i)
				for(int k=0;k<n;k++)
					dp[i][k]=min(dp[i][k],dp[j][k]+dp[i^j][k]);
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
					dp[i][j]=min(dp[i][j],dp[i][k]+dist[k][j]);
		}
		
		int res=INFTY;
		for(int i=0;i<n;i++)
			res=min(res,dp[(1<<hsize)-1][i]);
		cout<<n-(res+1)<<endl;
	}
	
	return 0;
}