#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using edge = struct {
  int to;
  ll cost;
};
long long combination[10001][10001];
int h, w;
char maze[100][100];
bool mazeVisit[100][100];
int mazeDis[100][100];
queue<pair<int, int>> mazeQ;
int ans = 0;
void solve() {
  cin >> h >> w;
  int ans = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> maze[i][j];
  for (int i = 0; i <= h + 1; i++)
    for (int j = 0; j <= w + 1; j++) mazeVisit[i][j] = true;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (maze[i][j] == '.') {
        for (int x = 0; x <= h + 1; x++) {
          for (int y = 0; y <= w + 1; y++) {
            if (maze[x][y] != '.') continue;
            mazeVisit[x][y] = false;
            mazeDis[x][y] = 0;
          }
        }
        mazeQ.push(make_pair(i, j));
        int x, y;
        while (!mazeQ.empty()) {
          pair<int, int> now = mazeQ.front();
          mazeQ.pop();
          x = now.first, y = now.second;
          mazeVisit[x][y] = true;
          if (!mazeVisit[x + 1][y]) mazeQ.push(make_pair(x + 1, y));
          mazeDis[x + 1][y] = mazeDis[x][y] + 1;
          if (!mazeVisit[x - 1][y]) mazeQ.push(make_pair(x - 1, y));
          mazeDis[x - 1][y] = mazeDis[x][y] + 1;
          if (!mazeVisit[x][y + 1]) mazeQ.push(make_pair(x, y + 1));
          mazeDis[x][y + 1] = mazeDis[x][y] + 1;
          if (!mazeVisit[x][y - 1]) mazeQ.push(make_pair(x, y - 1));
          mazeDis[x][y - 1] = mazeDis[x][y] + 1;
        }
        ans = max(ans, mazeDis[x][y]);
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  solve();
  return 0;
}
