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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;


const int inf = 1e9;
// Dreyfus-Wagner. O(4^k)
int steiner_tree(const vector<vector<PI> > &g, const VI &term) {
  int n = g.size();
  int k = term.size();
  vector<vector<int> > dist(n, vector<int>(n, inf));
  REP(i, 0, n) {
    REP(j, 0, g[i].size()) {
      PI wc = g[i][j];
      int w = wc.first, c = wc.second;
      dist[i][w] = min(dist[i][w], c);
    }
  }
  REP(i, 0, n) dist[i][i] = 0;
  REP(l, 0, n) {
    REP(i, 0, n) {
      REP(j, 0, n) {
        dist[i][j] = min(dist[i][j], dist[i][l] + dist[l][j]);
      }
    }
  }
  vector<vector<int> > dp(n, vector<int>(1 << k, inf));
  // base case: |bits| = 1
  REP(i, 0, k) {
    REP(j, 0, n) {
      dp[j][1 << i] = min(dp[j][1 << i], dist[term[i]][j]);
    }
  }
  REP(bits, 1, 1 << k) {
    // if popcount(bits) == 1 then skip
    if ((bits & -bits) == bits) continue;
    REP(i, 0, n) {
      REP(sub, 1, bits) {
        if ((sub & bits) != sub) continue;
        dp[i][bits] = min(dp[i][bits], dp[i][sub] + dp[i][bits - sub]);
      }
    }
    REP(i, 0, n) {
      REP(j, 0, n) {
        dp[i][bits] = min(dp[i][bits], dp[j][bits] + dist[i][j]);
      }
    }
  }
  int mi = inf;
  REP(i, 0, n) {
    mi = min(mi, dp[i][(1 << k) - 1]);
  }
  return mi;   
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  while(cin >> h >> w && h && w) {
    vector<VI> s(h, VI(w));
    REP(i, 0, h) {
      REP(j, 0, w) {
        cin >> s[i][j];
      }
    }
    vector<vector<PI> > g(h * w);
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    VI term;
    REP(i, 0, h) {
      REP(j, 0, w) {
        int v = i * w + j;
        if (s[i][j] == 1) term.push_back(v);
        REP(d, 0, 4) {
          int nx = i + dx[d];
          int ny = j + dy[d];
          if (nx < 0 || nx >= h || ny < 0 || ny >= h) continue;
          int u = nx * w + ny;
          g[v].push_back(PI(u, 1));
          g[u].push_back(PI(v, 1));
        }
      }
    }
    cout << h * w - 1 - steiner_tree(g, term) << endl;
  }
}