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<iostream>
#include<cstring>
using namespace std;
const int inf = 987654321;

// ツ氾アツ閉可づ個鳴ウツ古シツグツδ可フツづ可妥篠つオツ、ツタツーツミツナツδ逆sツづ個要ツ素ツづーツ全ツづ甘慊づ楪催渉ャツづ個姪伉づ個コツスツトツづーツ仰づ淞づゥ
#define REP(i, N) for(int i = 0; i < (int)(N); ++i)

const int MAX_N = 150;
int g[MAX_N][MAX_N];
int minimum_steiner_tree(int n, const vector<int> ts) {
  static int dp[1 << 12][MAX_N];
  memset(dp, 0, sizeof(dp));
  int m = ts.size();
  if( m < 2 ) return 0;

  REP(k, n) REP(i, n) REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  REP(i, m) REP(j, n) dp[1 << i][j] = g[ts[i]][j];

  for(int i = 1; i < 1 << m; i++) if((i - 1) & i) {
      REP(j, n) {
        dp[i][j] = inf;
        for(int k = (i - 1) & i; k > 0 ; k = (k - 1) & i)
          dp[i][j] = min(dp[i][j], dp[k][j] + dp[i ^ k][j]);
      }
      REP(j, n) REP(k, n) dp[i][j] = min(dp[i][j], dp[i][k] + g[k][j]);
    }
  return dp[(1 << m) - 1][ts[0]];
}

int main() {
  for(int R, C; cin >> R >> C, (R || C); ) {
    REP(i, MAX_N) REP(j, MAX_N) g[i][j] = inf;
    REP(i, MAX_N) g[i][i] = 0;

    int table[R][C];
    REP(r, R) REP(c, C) cin >> table[r][c];

    const int dr[] = {0, 1, -1, 0};
    const int dc[] = {1, 0, 0, -1};
    REP(r, R) REP(c, C) REP(k, 4) {
      int nr = r + dr[k];
      int nc = c + dc[k];
      if( 0 <= nr && nr < R && 0 <= nc && nc < C )
        g[r * C + c][nr * C + nc] = 1;
    }
    vector<int> ts;
    REP(r, R) REP(c, C) if( table[r][c] == 1 ) ts.push_back(r * C + c);

    int temp = minimum_steiner_tree(R * C, ts);
    cout << R * C - temp - 1 << endl;
  }
}