#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  while (1){
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0){
      break;
    }
    vector<vector<char>> c(h + 2, vector<char>(w + 2, 'x'));
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        cin >> c[i][j];
      }
    }
    vector<pair<int, int>> T;
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        if (c[i][j] == '*'){
          T.push_back(make_pair(i, j));
          c[i][j] = '.';
        }
        if (c[i][j] == 'o'){
          T.insert(T.begin(), make_pair(i, j));
          c[i][j] = '.';
        }
      }
    }
    int N = T.size();
    vector<vector<int>> E(N, vector<int>(N));
    for (int i = 0; i < N; i++){
      vector<vector<int>> d(h + 2, vector<int>(w + 2, INF));
      d[T[i].first][T[i].second] = 0;
      queue<pair<int, int>> Q;
      Q.push(make_pair(T[i].first, T[i].second));
      while (!Q.empty()){
        int y = Q.front().first;
        int x = Q.front().second;
        Q.pop();
        for (int j = 0; j < 4; j++){
          int y2 = y + dy[j];
          int x2 = x + dx[j];
          if (c[y2][x2] == '.' && d[y2][x2] == INF){
            d[y2][x2] = d[y][x] + 1;
            Q.push(make_pair(y2, x2));
          }
        }
      }
      for (int j = 0; j < N; j++){
        E[i][j] = d[T[j].first][T[j].second];
      }
    }
    bool ok = true;
    for (int j = 1; j < N; j++){
      if (E[0][j] == INF){
        ok = false;
      }
    }
    if (!ok){
      cout << -1 << endl;
    } else {
      vector<int> p(N);
      for (int j = 0; j < N; j++){
        p[j] = j;
      }
      int ans = INF;
      while (1){
        int sum = 0;
        for (int j = 0; j < N - 1; j++){
          sum += E[p[j]][p[j + 1]];
        }
        ans = min(ans, sum);
        next_permutation(p.begin(), p.end());
        if (p[0] > 0){
          break;
        }
      }
      cout << ans << endl;
    }
  }
}
