#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
constexpr Int INF = std::numeric_limits<Int>::max() / 20;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

const Vector<Int> dx{-1, 0, 1, 0}, dy{0, 1, 0, -1};

Bool solve() {
    Int w, h;
    std::cin >> w >> h;
    if (w == 0) return false;

    Vector<String> c(h);
    for (auto& s : c) std::cin >> s;

    Vector<Pair<Int, Int>> ps;
    for (Int x = 0; x < h; ++x) {
        for (Int y = 0; y < w; ++y) {
            if (c[x][y] == '*') {
                ps.emplace_back(x, y);
            } else if (c[x][y] == 'o') {
                ps.emplace(ps.begin(), x, y);
            }
        }
    }

    Int k = ps.size();
    Vector<Vector<Int>> dist(k, Vector<Int>(k));
    for (Int i = 0; i < k; ++i) {
        Int sx, sy;
        std::tie(sx, sy) = ps[i];

        Vector<Vector<Int>> dp(h, Vector<Int>(w, INF));
        dp[sx][sy] = 0;
        Queue<Pair<Int, Int>> que;
        que.emplace(sx, sy);

        while (!que.empty()) {
            Int x, y;
            std::tie(x, y) = que.front();
            que.pop();

            for (Int d = 0; d < 4; ++d) {
                Int nx = x + dx[d], ny = y + dy[d];
                if (nx < 0 || h <= nx || ny < 0 || w <= ny ||
                    c[nx][ny] == 'x' || dp[nx][ny] < INF) continue;

                dp[nx][ny] = dp[x][y] + 1;
                que.emplace(nx, ny);
            }
        }

        for (Int j = 0; j < k; ++j) {
            Int gx, gy;
            std::tie(gx, gy) = ps[j];
            dist[i][j] = dp[gx][gy];
        }
    }

    Int ans = INF;
    Vector<Int> order(k);
    std::iota(order.begin(), order.end(), 0);
    do {
        Int d = 0;
        for (Int i = 0; i < k - 1; ++i) {
            d += dist[order[i]][order[i + 1]];
        }
        ans = std::min(ans, d);
    } while (std::next_permutation(++order.begin(), order.end()));

    std::cout << (ans == INF ? -1 : ans) << std::endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3108