#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
static const int MAX_W = 20;
static const int MAX_H = 20;
static const int MAX_V = 10;
static const int INF = 1 << 30;

int w, h;
char field[MAX_H][MAX_W + 1];
int dist[MAX_V + 1][MAX_V + 1], dist2[MAX_H][MAX_W];
int dy[] = {0, -1, 0, 1};
int dx[] = {1, 0, -1, 0};

void bfs(int s, vector<P> va){
	dist[s][s] = 0;
	fill(dist2[0], dist2[h], INF);
	queue<P> qa;
	qa.push(va[s]);
	dist2[va[s].first][va[s].second] = 0;
	while(!qa.empty()){
		P cc = qa.front(); qa.pop();
		int cy = cc.first, cx = cc.second;
		for(int i = 0; i < 4; i++){
			int ny = cy + dy[i], nx = cx + dx[i];
			if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if(field[ny][nx] == 'x') continue;
			if(dist2[ny][nx] != INF) continue;
			qa.push(P(ny, nx));
			dist2[ny][nx] = dist2[cy][cx] + 1;
			if(field[ny][nx] == 'o' || field[ny][nx] == '*'){
				for(int j = 0; j < va.size(); j++){
					if(ny == va[j].first && nx == va[j].second){
						dist[s][j] = dist2[ny][nx];
						break;
					}
				}
			}
		}
	}
	return ;
}

int main(){
	for(;;){
		scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;
		vector<P> va;
		va.push_back(P(0, 0));
		int cnt = 1;
		for(int i = 0; i < h; i++){
			scanf("%s", field[i]);
			for(int j = 0; j < w; j++){
				if(field[i][j] == 'o') va[0] = P(i, j);
				if(field[i][j] == '*'){
					va.push_back(P(i, j));
					cnt++;
				}
			}
		}
		fill(dist[0], dist[cnt], INF);
		for(int i = 0; i < cnt; i++) bfs(i, va);
		bool flag = true;
		for(int i = 0; i < cnt; i++){
			for(int j = 0; j < cnt; j++){
				if(dist[i][j] == INF) flag = false;
			}
		}
		vector<int> vb(cnt - 1);
		for(int i = 0; i < cnt - 1; i++) vb[i] = i + 1;
		int res = INF;
		do{
			int sum = 0;
			for(int i = 0; i < vb.size(); i++){
				if(i == 0) sum += dist[0][vb[i]];
				else sum += dist[vb[i - 1]][vb[i]];
			}
			res = min(res, sum);
		}while(next_permutation(vb.begin(), vb.end()));
		printf("%d\n", (flag ? res : -1));
	}
	return 0;
}
