#include <bits/stdc++.h>
using namespace std;
int H, W;
char F[22][22];
int cost[22][22];
vector<pair<int, int>> bfs(int start, int end) {
  queue<pair<int, int>> K;
  K.push(make_pair(start, end));
  for (int x = 0; x < (H); x++) {
    for (int y = 0; y < (W); y++) {
      cost[x + 1][y + 1] = 10000;
    }
  }
  cost[start][end] = 0;
  while (!K.empty()) {
    auto p = K.front();
    K.pop();
    int x = p.first, y = p.second;
    if (F[x - 1][y] == '.' && cost[x - 1][y] > cost[x][y] + 1) {
      cost[x - 1][y] = cost[x][y] + 1;
      K.push(make_pair(x - 1, y));
    }
    if (F[x + 1][y] == '.' && cost[x + 1][y] > cost[x][y] + 1) {
      cost[x + 1][y] = cost[x][y] + 1;
      K.push(make_pair(x + 1, y));
    }
    if (F[x][y - 1] == '.' && cost[x][y - 1] > cost[x][y] + 1) {
      cost[x][y - 1] = cost[x][y] + 1;
      K.push(make_pair(x, y - 1));
    }
    if (F[x][y + 1] == '.' && cost[x][y + 1] > cost[x][y] + 1) {
      cost[x][y + 1] = cost[x][y] + 1;
      K.push(make_pair(x, y + 1));
    }
  }
  int res = 0;
  int resX = -1, resY = -1;
  vector<pair<int, int>>(Z);
  ;
  for (int x = 0; x < (H); x++) {
    for (int y = 0; y < (W); y++) {
      if (F[x + 1][y + 1] == '.') {
        if (res <= cost[x + 1][y + 1]) {
          res = cost[x + 1][y + 1];
        }
      }
    }
  }
  for (int x = 0; x < (H); x++) {
    for (int y = 0; y < (W); y++) {
      if (res == cost[x + 1][y + 1]) {
        (Z).push_back((make_pair(x + 1, y + 1)));
        ;
      }
    }
  }
  return Z;
}
int main() {
  cin >> H >> W;
  int start, end;
  for (int x = 0; x < (22); x++) {
    for (int y = 0; y < (22); y++) {
      F[x][y] = '#';
    }
  }
  for (int x = 0; x < (H); x++) {
    string s;
    cin >> s;
    for (int y = 0; y < (W); y++) {
      F[x + 1][y + 1] = s[y];
      if (s[y] == '.') {
        start = x + 1;
        end = y + 1;
      }
    }
  }
  auto res1 = bfs(start, end);
  int ans = 0;
  for (auto z : res1) {
    auto res2 = bfs(z.first, z.second);
    for (auto p : res2) {
      ans = max(cost[p.first][p.second], ans);
    }
  }
  cout << ans << endl;
  return 0;
}
