Problem:
Problem F: Cleaning Robot

Here, we want to solve path planning for a mobile robot cleaning a
rectangular room floor with furniture.

Consider the room floor paved with square tiles whose size fits
the cleaning robot (1 × 1).
There are 'clean tiles' and 'dirty tiles', and the robot can change
a 'dirty tile' to a 'clean tile' by visiting the tile.
Also there may be some obstacles (furniture) whose size fits a
tile in the room. If there is an obstacle on a tile, the robot cannot visit
it.
The robot moves to an adjacent tile with one move.
The tile onto which the robot moves must be one of four tiles
(i.e., east, west, north or south) adjacent to the tile where the
robot is present. The robot may visit a tile twice or more.

Your task is to write a program which computes the minimum number of
moves for the robot to change all 'dirty tiles' to 'clean tiles',
if ever possible.

Input

The input consists of multiple maps, each representing the size
and arrangement of the room. A map is given in the following format.

w h

c11 c12 c13 ... c1w

c21 c22 c23 ... c2w

...

ch1 ch2 ch3 ... chw

The integers w and h are the lengths of the two sides
of the floor of the room in terms of widths of floor tiles. w and h
are less than or equal to 20. The character cyx represents
what is initially on the tile with coordinates (x, y) as follows.

'.' : a clean tile

'*' : a dirty tile

'x' : a piece of furniture (obstacle)

'o' : the robot (initial position)

In the map the number of 'dirty tiles' does not exceed 10.
There is only one 'robot'.

The end of the input is indicated by a line containing two zeros.

Output

For each map, your program should output a line containing the minimum
number of moves. If the map includes 'dirty tiles' which the robot cannot reach,
your program should output -1.

Sample Input

7 5
.......
.o...*.
.......
.*...*.
.......
15 13
.......x.......
...o...x....*..
.......x.......
.......x.......
.......x.......
...............
xxxxx.....xxxxx
...............
.......x.......
.......x.......
.......x.......
..*....x....*..
.......x.......
10 10
..........
..o.......
..........
..........
..........
.....xxxxx
.....x....
.....x.*..
.....x....
.....x....
0 0

Output for the Sample Input

8
49
-1

Solution in C++14 (judge verdict: Accepted)

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int w, h; cin >> w >> h&&w;) {
		static char c[21][21];
		int n = 1;
		static int pi[11], pj[11];
		rep(i, 0, h)rep(j, 0, w) {
			cin >> c[i][j];
			if (c[i][j] == '*') {
				pi[n] = i;
				pj[n] = j;
				n++;
			}
			else if (c[i][j] == 'o')
				pi[0] = i, pj[0] = j;
		}
		static const int di[] = { 1,0,-1,0 };
		static const int dj[] = { 0,1,0,-1 };
		static int d[11][21][21];
		memset(d, 0x3f, sizeof(d));
		rep(i, 0, n) {
			d[i][pi[i]][pj[i]] = 0;
		}
		auto inrange = [&](int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; };
		rep(k, 0, n) {
			using P = pair<int, int>;
			queue<P> q;
			q.push(P(pi[k], pj[k]));
			for (int ci, cj; !q.empty();) {
				tie(ci, cj) = q.front(); q.pop();
				for (int i = 0; i < 4; i++) {
					int ni = ci + di[i], nj = cj + dj[i];
					if (!inrange(ni, nj))continue;
					if (c[ni][nj] == 'x')continue;
					if (d[k][ni][nj] != INF)continue;
					d[k][ni][nj] = d[k][ci][cj] + 1;
					q.emplace(ni, nj);
				}
			}
		}
		static int dp[1 << 11][11];
		memset(dp, 0x3f, sizeof(dp));
		dp[1][0] = 0;
		dump(n);
		for (int mask = 0; mask < (1 << n); mask++) {
			rep(i, 0, n) {
				rep(j, 0, n) {
					if (mask >> j & 1)continue;
					if (dp[mask][i] == INF || d[i][pi[j]][pj[j]] == INF)continue;
					dump(mask);
					chmin(dp[mask | (1 << j)][j], dp[mask][i] + d[i][pi[j]][pj[j]]);
				}
			}
		}
		int ans = INF;
		rep(i, 0, n)
			chmin(ans, dp[(1 << n) - 1][i]);
		cout << (ans == INF ? -1 : ans) << endl;
	}
	return 0;
}