#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
 
// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}
int dxy[5] = {-1,0,1,0,-1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int w, h;
  while(cin >> w >> h, w || h){
    vector<string> v;
    vector<pair<int, int>> p;
    map<pair<int, int>, int> mp;
    int cnt = 0;
    int sx, sy;
    for(int i=0; i<h; i++){
      string s; cin >> s;
      v.push_back(s);

      for(int j=0; j<w; j++){
        if(s[j] == 'o'){
          sy = i;
          sx = j;
        }
      }
    }
    mp[make_pair(sy, sx)] = cnt++;

    p.emplace_back(sy,sx);
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if(v[i][j] == '*'){
          p.emplace_back(i, j);

          mp[make_pair(i, j)] = cnt++;
        }
      }
    }
    vector<vector<pair<int, int>>> g(p.size());
    bool f = true;
    for(int i=0; i<p.size(); i++){
      queue<int> q;
      vector<int> dist(h*w, INT_MAX);
      int y = p[i].first, x = p[i].second;
      dist[y*w + x] = 0;
      q.push(y*w + x);
      while(q.size()){
        int vv = q.front();
        q.pop();

        int yy = vv/w, xx = vv%w;

        for(int i=0; i<4; i++){
          int ny = yy + dxy[i], nx = xx + dxy[i+1];

          if(ny >= 0 && ny < h && nx >= 0 && nx < w && dist[ny*w+nx] == INT_MAX && v[ny][nx] != 'x'){
            dist[ny*w + nx] = dist[yy*w+xx] + 1;
            q.push(ny*w + nx);
          }
        }
      }

      for(int j=0; j<p.size(); j++){
        int yy = p[j].first, xx = p[j].second;
        if(dist[yy*w+xx] == INT_MAX){
          f = false;
        }else{
          g[i].push_back(make_pair(j, dist[yy*w+xx]));
        }
      }
    }

    if(!f) {
      cout << -1 << endl;
      continue;
    }

    vector<vector<ll>> dp(1<<p.size(), vector<ll>(p.size(), INT_MAX));
    dp[(1<<0)][0] = 0;
    for(int i=0; i<p.size(); i++){
      int v = g[0][i].first;
      int cost = g[0][i].second;
      dp[(1<<i) | (1<<0)][i] = cost;
    }

    for(int bit=0; bit < (1<<p.size()); bit++){

      for(int i=0; i<p.size(); i++){


        if(bit >> i & 1){

          for(int j=0; j<p.size(); j++){
            if(!(bit >> j & 1)){
              
              dp[bit | (1 << j)][j] = min(dp[bit | (1 << j)][j], dp[bit][i] + g[i][j].second);
            }
          }
        }
      }
    }

    ll ans = INT_MAX;
    for(int i=0; i<p.size(); i++){
      ans = min(ans, dp[(1<<p.size())-1][i]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3272