#include <bits/stdc++.h>
using namespace std;
char grid[21][21];
class QItem {
 public:
  int row;
  int col;
  int dist;
  QItem(int x, int y, int w) : row(x), col(y), dist(w) {}
};
int minDistance(int N, int M) {
  QItem source(0, 0, 0);
  bool visited[N][M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (grid[i][j] == '0')
        visited[i][j] = true;
      else
        visited[i][j] = false;
      if (grid[i][j] == 's') {
        source.row = i;
        source.col = j;
      }
    }
  }
  queue<QItem> q;
  q.push(source);
  visited[source.row][source.col] = true;
  while (!q.empty()) {
    QItem p = q.front();
    q.pop();
    if (grid[p.row][p.col] == 'd') return p.dist;
    if (p.row - 1 >= 0 && visited[p.row - 1][p.col] == false) {
      q.push(QItem(p.row - 1, p.col, p.dist + 1));
      visited[p.row - 1][p.col] = true;
    }
    if (p.row + 1 < N && visited[p.row + 1][p.col] == false) {
      q.push(QItem(p.row + 1, p.col, p.dist + 1));
      visited[p.row + 1][p.col] = true;
    }
    if (p.col - 1 >= 0 && visited[p.row][p.col - 1] == false) {
      q.push(QItem(p.row, p.col - 1, p.dist + 1));
      visited[p.row][p.col - 1] = true;
    }
    if (p.col + 1 < M && visited[p.row][p.col + 1] == false) {
      q.push(QItem(p.row, p.col + 1, p.dist + 1));
      visited[p.row][p.col + 1] = true;
    }
  }
  return -1;
}
int main() {
  vector<string> ar;
  int h, w, j;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string buf;
    cin >> buf;
    ar.push_back(buf);
  }
  for (int i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (ar[i][j] = '.')
        grid[i][j] = '*';
      else
        grid[i][j] = '0';
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (grid[i][j] = '*') {
        grid[i][j] = 's';
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            if (grid[k][l] != 's' && grid[k][l] == '*') {
              grid[k][l] = 'd';
              int temp = minDistance(h, w);
              ans = max(ans, temp);
              grid[k][l] = '*';
            }
          }
        }
        grid[i][j] = '*';
      }
    }
  }
  cout << ans;
  return 0;
}
