#include <bits/stdc++.h>
using namespace std;
char city[100][100];
bool done[100][100];
int keiro[100][100];
int dist[100][100];
int h, w;
int bfs(int x, int y) {
  queue<pair<int, int> > que;
  int distance = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      done[i][j] = false;
    }
  }
  pair<int, int> hoge;
  hoge.first = x;
  hoge.second = y;
  que.push(hoge);
  dist[x][y] = 0;
  done[x][y] = true;
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    if (v.first + 1 < h && v.first + 1 >= 0 && v.second < w && v.second >= 0 &&
        !done[v.first + 1][v.second] && city[v.first + 1][v.second] != '#') {
      hoge.first = v.first + 1;
      hoge.second = v.second;
      que.push(hoge);
      dist[hoge.first][hoge.second] = dist[v.first][v.second] + 1;
      distance = max(distance, dist[hoge.first][hoge.second]);
      done[hoge.first][hoge.second] = true;
    }
    if (v.first - 1 < h && v.first - 1 >= 0 && v.second < w && v.second >= 0 &&
        !done[v.first - 1][v.second] && city[v.first - 1][v.second] != '#') {
      hoge.first = v.first - 1;
      hoge.second = v.second;
      que.push(hoge);
      dist[hoge.first][hoge.second] = dist[v.first][v.second] + 1;
      distance = max(distance, dist[hoge.first][hoge.second]);
      done[hoge.first][hoge.second] = true;
    }
    if (v.first < h && v.first >= 0 && v.second + 1 < w && v.second + 1 >= 0 &&
        !done[v.first][v.second + 1] && city[v.first][v.second + 1] != '#') {
      hoge.first = v.first;
      hoge.second = v.second + 1;
      que.push(hoge);
      dist[hoge.first][hoge.second] = dist[v.first][v.second] + 1;
      distance = max(distance, dist[hoge.first][hoge.second]);
      done[hoge.first][hoge.second] = true;
    }
    if (v.first < h && v.first >= 0 && v.second - 1 < w && v.second - 1 >= 0 &&
        !done[v.first][v.second - 1] && city[v.first][v.second - 1] != '#') {
      hoge.first = v.first;
      hoge.second = v.second - 1;
      que.push(hoge);
      dist[hoge.first][hoge.second] = dist[v.first][v.second] + 1;
      distance = max(distance, dist[hoge.first][hoge.second]);
      done[hoge.first][hoge.second] = true;
    }
  }
  return distance;
}
int main() {
  cin >> h >> w;
  char temp;
  int startx, starty, goalx, goaly;
  bool judge = false;
  int ans = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> temp;
      city[i][j] = temp;
      done[i][j] = false;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < h; j++) {
      if (city[i][j] != '#') {
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans << endl;
}
