import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int H, W;
    bool[][] F;
    bool input() {
        scanf("%d %d\n", &H, &W);
        if (H == 0 && W == 0) return false;
        F = new bool[][H];
        foreach (i; 0 .. H) {
            F[i] = readln.chomp.split(" ").map!((x) => cast(bool)x.to!int).array;
        }
        return true;
    }
    void solve() {
        int C = 0;
        auto I = new int[][](H, W);
        foreach (i; 0 .. H) I[i][] = -1;
        int[] Y, X;
        foreach (int i; 0 .. H) foreach (int j; 0 .. W) {
            if (F[i][j]) {
                Y ~= i;
                X ~= j;
                I[i][j] = C++;
            }
        }

        int dist(int y1, int x1, int y2, int x2) {
            return abs(y1 - y2) + abs(x1 - x2);
        }

        const INF = 1<<28;
        auto dp = new int[][][](H, W, 1 << C);
        foreach (y; 0 .. H) {
            foreach (x; 0 .. W) {
                foreach (bit; 0 .. (1 << C)) {
                    dp[y][x][bit] = INF;
                }
            }
        }
        foreach (y; 0 .. H) {
            foreach (x; 0 .. W) {
                foreach (k; 0 .. C) {
                    dp[y][x][1 << k] = dist(y, x, Y[k], X[k]);
                }
            }
        }
        foreach (y; 0 .. H) {
            foreach (x; 0 .. W) {
                foreach (y1; 0 .. H) {
                    foreach (x1; 0 .. W) {
                        foreach (s; 1 .. (1 << C)) {
                            foreach (s1; 1 .. s) {
                                if ((s | s1) != s) continue;
                                if (s == s1) continue;
                                int s2 = s ^ s1;
                                dp[y][x][s] = min(dp[y][x][s], dp[y1][x1][s1] + dp[y1][x1][s2] + dist(y, x, y1, x1));
                            }
                        }
                    }
                }
            }
        }
        int Ans = INF;
        foreach (y; 0 .. H) {
            foreach (x; 0 .. W) {
                Ans = min(Ans, dp[y][x][(1 << C) - 1]);
            }
        }
        writeln(H * W - Ans - 1);
    }
    while (input) solve;
}