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 <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string normalize(string s, bool isAdd, bool isUp, bool isLeft)
{
    if(isAdd){
        if(isUp && s[0] != '.')
            replace(s.rbegin(), s.rend(), s[0], 'Z');
        if(isLeft && s[s.size()-1] != '.')
            replace(s.begin(), s.end(), s[s.size()-1], 'Z');
        s += 'Z';
    }else{
        if(s[0] != '.' && count(s.begin(), s.end(), '.') == s.size() - 1)
            return "";
        s += '.';
    }
    if(s[0] != '.' && count(s.begin(), s.end(), s[0]) == 1)
        return "";
    s = s.substr(1);

    map<char, char> to;
    for(unsigned i=0; i<s.size(); ++i){
        if(s[i] == '.')
            continue;
        if(to.find(s[i]) == to.end()){
            char c = 'A' + to.size();
            to[s[i]] = c;
        }
        s[i] = to[s[i]];
    }
    return s;
}

int main()
{
    for(;;){
        int h, w;
        cin >> h >> w;
        if(h == 0)
            return 0;
        int sum = h * w;

        vector<vector<int> > chocolate(h, vector<int>(w));
        vector<int> cy, cx;
        map<int, int> yIndex, xIndex;
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                cin >> chocolate[y][x];
                if(chocolate[y][x] == 1){
                    cy.push_back(y);
                    cx.push_back(x);
                    yIndex[y];
                    xIndex[x];
                }
            }
        }

        vector<int> dy, dx;
        int prev = 0;
        for(map<int, int>::iterator it=yIndex.begin(); it!=yIndex.end(); ++it){
            dy.push_back(it->first - prev);
            it->second = dy.size() - 1;
            prev = it->first;
        }
        prev = 0;
        for(map<int, int>::iterator it=xIndex.begin(); it!=xIndex.end(); ++it){
            dx.push_back(it->first - prev);
            it->second = dx.size() - 1;
            prev = it->first;
        }
        dy[0] = dx[0] = 1;

        h = dy.size();
        w = dx.size();
        chocolate.assign(h, vector<int>(w, 0));
        for(unsigned i=0; i<cy.size(); ++i)
            chocolate[yIndex[cy[i]]][xIndex[cx[i]]] = 1;

        map<string, int> dp;
        dp[string(w, '.')] = 0;
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                map<string, int> nextDp;
                for(map<string, int>::iterator it=dp.begin(); it!=dp.end(); ++it){
                    string s = it->first;

                    if(chocolate[y][x] == 0){
                        string t = normalize(s, false, false, false);
                        if(t != ""){
                            if(nextDp.find(t) == nextDp.end())
                                nextDp[t] = it->second;
                            else
                                nextDp[t] = min(nextDp[t], it->second);
                        }
                    }

                    for(int i=0; i<4; ++i){
                        bool isUp = i%2;
                        bool isLeft = i/2;
                        if(x == 0 && isLeft)
                            continue;

                        int cost = 1;
                        if(isUp)
                            cost += dy[y] - 1;
                        if(isLeft)
                            cost += dx[x] - 1;

                        string t = normalize(s, true, isUp, isLeft);
                        if(t != ""){
                            if(nextDp.find(t) == nextDp.end())
                                nextDp[t] = it->second + cost;
                            else
                                nextDp[t] = min(nextDp[t], it->second + cost);
                        }
                    }
                }
                dp.swap(nextDp);
            }
        }

        int ret = INT_MAX;
        for(map<string, int>::iterator it=dp.begin(); it!=dp.end(); ++it){
            string s = it->first;
            if(s.find('B') == string::npos)
                ret = min(ret, it->second);
        }
        ret = sum - ret;
        cout << ret << endl;
    }
}