#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using Int = ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    bool solve() {
        input();
        Int w, h;
        cin >> w >> h;
        if (w == 0) return false;

        vector<string> c(h);
        rep(i, 0, h) cin >> c[i];

        auto conv = [&](Int r, Int c) {
            return r * w + c;
        };

        vector<vector<Int>> dist(w * h, vector<Int>(w * h, INF));
        for (Int i = 0; i + 1 < h; ++i) {
            for (Int j = 0; j < w; ++j) {
                if (c[i][j] != 'x' && c[i + 1][j] != 'x') {
                    Int f = conv(i, j);
                    Int t = conv(i + 1, j);
                    dist[f][t] = dist[t][f] = 1;
                }
            }
        }

        for (Int i = 0; i < h; ++i) {
            for (Int j = 0; j + 1 < w; ++j) {
                if (c[i][j] != 'x' && c[i][j + 1] != 'x') {
                    Int f = conv(i, j);
                    Int t = conv(i, j + 1);
                    dist[f][t] = dist[t][f] = 1;
                }
            }
        }
        for (Int i = 0; i < w * h; ++i) {
            dist[i][i] = 0;
        }

        for (int k = 0; k < w * h; ++k) {
            for (int i = 0; i < w * h; ++i) {
                for (int j = 0; j < w * h; ++j) {
                    if (dist[i][k] + dist[k][j] < dist[i][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        Int st;
        vector<Int> yogore;
        for (Int i = 0; i < h; ++i) {
            for (Int j = 0; j < w; ++j) {
                if (c[i][j] == 'o') st = conv(i, j);
                else if (c[i][j] == '*') yogore.push_back(conv(i, j));
            }
        }

        sort(all(yogore));
        Int ans = INF;
        do {
            vector<Int> arr;
            arr.push_back(st);
            for (auto e : yogore) arr.push_back(e);
            Int tmp = 0;
            for (int i = 0; i + 1 < arr.size(); ++i) {
                tmp += dist[arr[i]][arr[i + 1]];
            }
            chmin(ans, tmp);
        } while (next_permutation(all(yogore)));

        if (ans == INF) {
            cout << -1 << endl;
        } else {
            cout << ans << endl;
        }

        return true;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (Solve().solve());


    return 0;
}



Measured memory_bytes: 3996