### constant

INF = 1 << 30

DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

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

  wh = w * h

  tls = wh.times.map{0}
  ndtl = 0
  spos = nil

  for y in (0...h)
    line = gets.strip
    for x in (0...w)
      pos = y * w + x
      case line[x]
      when '*'
        ndtl += 1
        tls[pos] = ndtl
      when 'x'
        tls[pos] = -1
      when 'o'
        spos = pos
      end
    end
  end
  #p tls
  #p spos

  dbits = (1 << ndtl) - 1

  dists = wh.times.map{(dbits + 1).times.map{INF}}
  dists[spos][dbits] = 0
  q = [[spos, dbits]]

  min_dist = INF

  while ! q.empty?
    upos, ubits = q.shift
    ud = dists[upos][ubits]

    if ubits == 0
      min_dist = ud if min_dist > ud
      next
    end

    ux = upos % w
    uy = upos / w

    DXYS.each do |dx, dy|
      vx = ux + dx
      vy = uy + dy
      vpos = vy * w + vx

      if vx >= 0 && vx < w && vy >= 0 && vy < h && tls[vpos] >= 0
        vbits = ubits
        if tls[vpos] > 0
          vbits &= ~(1 << (tls[vpos] - 1))
        end

        vd = ud + 1
        if dists[vpos][vbits] > vd
          dists[vpos][vbits] = vd
          q << [vpos, vbits]
        end
      end
    end
  end

  puts (min_dist >= INF ? -1 : min_dist)
  #p dists
end