#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;
    }
}