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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

int DreyfusWagner(const vvi& _dist,const vi& ts)
{
	int n=_dist.size();
	vvi dist=_dist;
	rep(k,n) rep(i,n) rep(j,n)
		dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	
	int tsize=ts.size();
	vvi dp(1<<tsize,vi(n,INFTY));
	rep(i,tsize) rep(j,n)
		dp[1<<i][j]=dist[ts[i]][j];
	rep(i,1<<tsize){
		for(int j=i;j;j=i&(j-1)) rep(k,n)
			dp[i][k]=min(dp[i][k],dp[j][k]+dp[i^j][k]);
		rep(j,n) rep(k,n)
			dp[i][j]=min(dp[i][j],dp[i][k]+dist[k][j]);
	}
	return *min_element(all(dp.back()));
}

int main()
{
	for(int h,w;scanf("%d%d",&h,&w),h|w;){
		int n=h*w;
		vvi dist(n,vi(n,INFTY));
		vi hs;
		rep(i,h) rep(j,w){
			int x; scanf("%d",&x);
			if(x==1)
				hs.push_back(i*w+j);
			dist[i*w+j][i*w+j]=0;
			int di[]={-1,1,0,0},dj[]={0,0,-1,1};
			rep(k,4){
				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;
			}
		}
		int res=DreyfusWagner(dist,hs);
		printf("%d\n",n-(res+1));
	}
	
	return 0;
}