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 <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define pb push_back
#define mp make_pair
#define SZ(a) ((int)(a.size()))
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> PI;


int h,w;
int cost[200][200];
int dp[1<<6][200];
int n;

int main(int argc, char *argv[])
{
  while(cin >> h >> w, h){
    n = h * w;
    rep(i,n)rep(j,n) cost[i][j] = 1e8;
    rep(i,n) cost[i][i] = 0;
    
    vector<int> ter;
    
    rep(i,h)rep(j,w){
      if(i+1 < h)
        cost[i*w+j][(i+1)*w+j] = cost[(i+1)*w+j][i*w+j] = 1;
      
      if(j+1 < w)
        cost[i*w+j][(i)*w+j+1] = cost[(i)*w+j+1][i*w+j] = 1;
      
      int  t;
      cin >> t;
      if(t) ter.pb(i*w+j);
    }
    
    rep(k,n)rep(i,n)rep(j,n)
      cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
    
    rep(i,1<<SZ(ter)) rep(j,n) dp[i][j] = 1e8;
    
    rep(i,SZ(ter))rep(j,n) dp[1<<i][j] = cost[ter[i]][j];
    
    // rep(i,n){
    //   rep(j,n){
    //     cout << cost[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    
    {
      for(int S = 0; S < (1<<SZ(ter)); ++S){
        if((S&(S-1)) == 0) continue;
        int sub = S-1;
        do{
          rep(i,n)
            dp[S][i] = min(dp[S][i], dp[sub][i] + dp[S^sub][i]);
          sub = S & (sub-1);
        }while(sub);
        rep(p,n)rep(q,n)
          dp[S][p] = min(dp[S][p],dp[S][q] + cost[q][p]);
      }
    }
    
    cout << n - dp[(1<<SZ(ter))-1][ter[0]] - 1 << endl;
  }
}