#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<int> dy(4), dx(4);
vector<vector<char>> S(30, vector<char>(30));
int rev;
void BFS(int sy, int sx) {
  vector<vector<int>> dist(30, vector<int>(30, -1));
  dist[sy][sx] = 0;
  queue<pair<int, int>> que;
  pair<int, int> p = {sy, sx};
  que.push(p);
  while (!que.empty()) {
    pair<int, int> s = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ty = s.first + dy[i];
      int tx = s.second + dx[i];
      if (S[ty][tx] == '#') {
        continue;
      }
      if (ty <= 0 || tx <= 0 || ty > H || tx > W) {
        continue;
      }
      if (dist[ty][tx] != -1) {
        continue;
      }
      dist[ty][tx] = dist[s.first][s.second] + 1;
      rev = max(rev, dist[ty][tx]);
      pair<int, int> q = {ty, tx};
      que.push(q);
    }
  }
}
int main() {
  cin >> H >> W;
  dy[0] = 0;
  dx[0] = 1;
  dy[1] = 1;
  dx[1] = 0;
  dy[2] = 0;
  dx[2] = -1;
  dy[3] = -1;
  dx[3] = 0;
  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W; w++) {
      cin >> S[h][w];
    }
  }
  int ans = 0;
  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W; w++) {
      rev = 0;
      BFS(h, w);
      ans = max(ans, rev);
    }
  }
  cout << ans << endl;
  return 0;
}
