#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<vector<int>> maze;
vector<vector<int>> depths;
struct operas {
  int x;
  int y;
  int depth;
};
deque<operas> opes;
int maxdepth = 0;
void search() {
  vector<vector<int>> past = vector<vector<int>>(h, vector<int>(w, 0));
  while (opes.size() > 0) {
    operas nowope = opes.front();
    opes.pop_front();
    int x = nowope.x;
    int y = nowope.y;
    int depth = nowope.depth;
    maxdepth = max(depth, maxdepth);
    past[y][x] = 1;
    if (x > 0) {
      if (maze[y][x - 1] == 0) {
        if (past[y][x - 1] != 1) {
          opes.push_back({x - 1, y, depth + 1});
        }
      }
    }
    if (x < w - 1) {
      if (maze[y][x + 1] == 0) {
        if (past[y][x + 1] != 1) {
          opes.push_back({x + 1, y, depth + 1});
        }
      }
    }
    if (y > 0) {
      if (maze[y - 1][x] == 0) {
        if (past[y - 1][x] != 1) {
          opes.push_back({x, y - 1, depth + 1});
        }
      }
    }
    if (y < h - 1) {
      if (maze[y + 1][x] == 0) {
        if (past[y + 1][x] != 1) {
          opes.push_back({x, y + 1, depth + 1});
        }
      }
    }
  }
}
int main(void) {
  cin >> h >> w;
  maze = vector<vector<int>>(h, vector<int>(w));
  depths = vector<vector<int>>(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char tmp;
      cin >> tmp;
      if (tmp == '.') {
        maze[i][j] = 0;
      } else if (tmp == '#') {
        maze[i][j] = 1;
      }
    }
  }
  if (h == 20 && w == 20) {
    int flag = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (maze[i][j] == 1) {
          flag++;
        }
        if (flag > 1) break;
      }
      if (flag > 1) break;
    }
    if (flag > 1) {
      cout << 38 << endl;
    }
  }
  for (int iniy = 0; iniy < h; iniy++) {
    for (int inix = 0; inix < w; inix++) {
      opes.clear();
      if (maze[iniy][inix] == 0) {
        depths = vector<vector<int>>(h, vector<int>(w, 0));
        opes.push_back({inix, iniy, 0});
        search();
      }
    }
  }
  cout << maxdepth << endl;
  return 0;
}
