#include<bits/stdc++.h>
#define INF (1e9)
#define N 20
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;

int w,h,idlen,sid,ans;
string s[N];
vector<int> id;
vector<P> edge[11];

int bfs(int sy,int sx,int gy,int gx){
  int d[N][N];
  int dy[4]={-1,0,1,0};
  int dx[4]={0,1,0,-1};
  queue<P1> q;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)d[i][j]=INF;
  d[sy][sx]=0;
  q.push(P1(0,P(sy,sx)));
  while(!q.empty()){
    P1 t=q.front(); q.pop();
    int c=t.first;
    int y=t.second.first,x=t.second.second;
    if(d[y][x]<c)continue;
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx)continue;
      if(s[ny][nx]=='x')continue;
      if(d[ny][nx]>c+1){
	d[ny][nx]=c+1;
	q.push(P1(d[ny][nx],P(ny,nx)));
      }
    }
  }
  return d[gy][gx];
}

int dijkstra(){
  
  int d[(1<<idlen)][idlen];
  
  priority_queue<P1,vector<P1>,greater<P1> > q;
  
  for(int i=0;i<(1<<idlen);i++)
    for(int j=0;j<idlen;j++)d[i][j]=INF;
  
  
  d[(1<<sid)][sid]=0;
  
  q.push(P1(0,P((1<<sid),sid)));
  
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int S=t.second.first;
    int c=t.first,u=t.second.second;
    
    if(d[S][u]<c)continue;
    
    if(S==(1<<idlen)-1)return c;
    
    for(int i=0;i<(int)edge[u].size();i++){
      int nu=edge[u][i].first;
      int nc=edge[u][i].second;
      if((S&(1<<nu)))continue;
      if(d[(S|(1<<nu))][nu]>c+nc){
	d[(S|(1<<nu))][nu]=c+nc;
	q.push(P1(c+nc,P((S|(1<<nu)),nu)));
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h)break;
    for(int i=0;i<h;i++){
      cin>>s[i];
      for(int j=0;j<w;j++){
	if(s[i][j]=='.'||s[i][j]=='x')continue;
	if(s[i][j]=='o')sid=id.size();
	id.push_back(w*i+j);
      }
    }
    idlen=id.size();
    for(int i=0;i<idlen;i++)
      for(int j=i;j<idlen;j++){
	if(i==j)continue;
	int y1=id[i]/w,x1=id[i]%w;
	int y2=id[j]/w,x2=id[j]%w;
	int d=bfs(y1,x1,y2,x2);
	edge[i].push_back(P(j,d));
	edge[j].push_back(P(i,d));
      }
    ans=dijkstra();
    if(ans!=INF)cout<<ans<<endl;
    else cout<<-1<<endl;
    id.clear();
    for(int i=0;i<idlen;i++)edge[i].clear();
  }
  return 0;
}