#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<vector<char>> S;
int bfs(int sy, int sx) {
  queue<pair<int, int>> Q;
  Q.push(make_pair(sy, sx));
  vector<vector<int>> searched(H + 1, vector<int>(W + 1, -1));
  searched[sy][sx] = 0;
  int longest = 0;
  while (!Q.empty()) {
    int qy = Q.front().first;
    int qx = Q.front().second;
    for (int i = 0; i < 4; ++i) {
      int ty = qy, tx = qx;
      if (i == 0)
        ty--;
      else if (i == 1)
        tx++;
      else if (i == 2)
        ty++;
      else if (i == 3)
        tx--;
      if (ty <= 0 || ty > H || tx <= 0 || tx > W) continue;
      if (searched[ty][tx] == -1) {
        if (S[ty][tx] == '#') {
          searched[ty][tx] = -2;
          continue;
        }
        searched[ty][tx] = searched[qy][qx] + 1;
        longest = max(longest, searched[ty][tx]);
        Q.push(make_pair(ty, tx));
      }
    }
    Q.pop();
  }
  return longest;
}
int main(void) {
  cin >> H >> W;
  S = vector<vector<char>>(H + 1, vector<char>(W + 1));
  for (int y = (1); y < (int)(H + 1); ++y) {
    string s;
    cin >> s;
    for (int x = (1); x < (int)(W + 1); ++x) {
      S[y][x] = s[x - 1];
    }
  }
  int longest = 0;
  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      longest = max(longest, bfs(y, x));
    }
  }
  cout << longest << endl;
  return 0;
}
