#include <bits/stdc++.h>
using namespace std;
static const int MV = 100;
int main() {
  while (1) {
    int w, h, Gcount = 0, sum = 0;
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    char M[h][w];
    int A[h][w];
    queue<pair<int, int> > Q;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> M[i][j];
        A[i][j] = MV;
        if (M[i][j] == '*') Gcount++;
        if (M[i][j] == 'o') {
          Q.push(make_pair(i, j));
          A[i][j] = 0;
        }
      }
    }
    while (Gcount != 0 || Q.empty()) {
      if (Q.empty()) break;
      int Dy[4] = {1, 0, -1, 0}, Dx[4] = {0, 1, 0, -1}, ny, nx;
      M[Q.front().first][Q.front().second] = '+';
      for (int i = 0; i < 4; i++) {
        ny = Q.front().first + Dy[i];
        nx = Q.front().second + Dx[i];
        if (M[ny][nx] == '.' && 0 <= nx && nx < w && 0 <= ny && ny < h) {
          Q.push(make_pair(ny, nx));
          M[ny][nx] = '+';
          A[ny][nx] = A[Q.front().first][Q.front().second] + 1;
        }
        if (M[ny][nx] == '*' && 0 <= nx && nx < w && 0 <= ny && ny < h) {
          Gcount--;
          M[ny][nx] = '+';
          sum += A[Q.front().first][Q.front().second] + 1;
          for (int j = 0; j < h; j++) {
            for (int k = 0; k < w; k++) {
              A[j][k] = MV;
              if (M[j][k] == '+') {
                M[j][k] = '.';
              }
            }
          }
          int q = Q.size();
          for (int j = 1; j < q; j++) {
            Q.pop();
          }
          Q.push(make_pair(ny, nx));
          A[ny][nx] = 0;
          i = 4;
        }
      }
      Q.pop();
    }
    if (sum == 0)
      cout << -1 << endl;
    else
      cout << sum << endl;
  }
}
