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<vector<int> > Matrix;
const int INF = (1<<28);

int minimumSteinerTree(const vector<int>& T, const Matrix& m){
  if(T.size() <= 1) return 0;
  Matrix mat = m;
 
  for(int k = 0; k < (int)mat.size(); k++)
    for(int i = 0; i < (int)mat.size(); i++)
      for(int j = 0; j < (int)mat.size(); j++)
	mat[i][j] = min(mat[i][j],mat[i][k]+mat[k][j]);

   int Opt[(1<<T.size())][m.size()];

  for(int i = 0; i < (1<<T.size()); i++)
    for(int j = 0; j < (int)m.size(); j++) Opt[i][j] = INF;

  for(int i = 0; i < (int)T.size(); i++)
    for(int j = 0; j < (int)m.size(); j++)
      Opt[(1<<i)][j] = mat[T[i]][j];
  

  for(int i = 1; i < (1<<T.size()); i++){
    if(!(i & (i-1))) continue;
    
    for(int j = 0; j < (int)m.size(); j++)
      for(int k = 0; k < i; k++)
	if((k|i) == i) Opt[i][j] = min(Opt[i][j],Opt[k][j]+Opt[i-k][j]);

    for(int j = 0; j < (int)m.size(); j++)
      for(int k = 0; k < (int)m.size(); k++)
	Opt[i][j] = min(Opt[i][j], Opt[i][k]+mat[j][k]);
  }

  int ans = INF;
  for(int i = 0; i < (1<<T.size()); i++)
    for(int j = 0; j < (int)m.size(); j++)
      ans = min(ans,Opt[i][j]+Opt[((1<<T.size())-1)-i][j]);
  return ans;
}

const int MAX = 15;
int H,W,field[MAX][MAX];

bool isInside(int h, int w){ return 0<=h&&h<H&&0<=w&&w<W;}
int main(){
  while(cin >> H >> W && H+W){

    vector<int> V;
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++){
	cin >> field[i][j];
	if(field[i][j] == 1) V.push_back(i*W+j);
      }

    Matrix mat(H*W,vector<int>(H*W));
    
    for(int i = 0; i < H*W; i++)
      for(int j = 0; j < H*W; j++) mat[i][j] = INF;

    int dx[] = {-1,1,0,0};
    int dy[] = {0,0,1,-1};
    for(int i = 0; i < H*W; i++)
      for(int j = 0; j < 4; j++){
	int h = i/W;
	int w = i%W;
	h += dy[j];
	w += dx[j];
	if(isInside(h,w)) mat[i][h*W+w] = 1;
      }

    for(int i = 0; i < H*W; i++) mat[i][i] = 0;
    cout << H*W-minimumSteinerTree(V,mat)-1 << endl;
  }
  return 0;
}