### constant

MAX_INT = (1 << 29)

### subroutines

def minimum_steiner_tree(ts, gmat)
  n = gmat.length
  nts = ts.length

  return 0 if nts <= 1

  dmat = (0...n).map{|y| (0...n).map{|x| (y == x) ? 0 : gmat[y][x]}}

  for k in (0...n)
    for i in (0...n)
      for j in (0...n)
        dmat[i][j] = [dmat[i][j], dmat[i][k] + dmat[k][j]].min
      end
    end
  end

  opt = (1 << nts).times.map{n.times.map{MAX_INT}}

  for p in (0...nts)
    for q in (0...n)
      opt[1 << p][q] = dmat[ts[p]][q]
    end
  end

  for s in (1...(1 << nts))
    next if (s & (s - 1)) == 0

    for p in (0...n)
      for e in (0...s)
        if (e | s) == s
          opt[s][p] = [opt[s][p], opt[e][p] + opt[s - e][p]].min
        end
      end
    end

    for p in (0...n)
      for q in (0...n)
        opt[s][p] = [opt[s][p], opt[s][q] + dmat[q][p]].min
      end
    end
  end

  ans = MAX_INT

  for s in (0...(1 << nts))
    for q in (0...n)
      ans = [ans, opt[s][q] + opt[(1 << nts) - 1 - s][q]].min
    end
  end

  ans
end

### main

loop do
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0

  hw = h * w
  ts = []
  gmat = hw.times.map{hw.times.map{MAX_INT}}

  for y in (0...h)
    line = gets.strip.split

    for x in (0...w)
      id = y * w + x

      ts << id if line[x] == '1'

      if x > 0
        gmat[id][id - 1] = gmat[id - 1][id] = 1
      end
      if x < w - 1
        gmat[id][id + 1] = gmat[id + 1][id] = 1
      end
      if y > 0
        gmat[id][id - w] = gmat[id - w][id] = 1
      end
      if y < h - 1
        gmat[id][id + w] = gmat[id + w][id] = 1
      end
    end
  end
  #p gmat

  mst = minimum_steiner_tree(ts, gmat)
  puts (hw - mst - 1)
end