#include <bits/stdc++.h>
using namespace std;
int h, w;
int biggest = 0;
int inf = 100000000;
void wid(int startX, int startY, int goalX, int goalY,
         vector<vector<char>> mp) {
  if (startX == goalX && startY == goalY) return;
  queue<pair<int, int>> que;
  pair<int, int> start = make_pair(startX, startY);
  pair<int, int> goal = make_pair(goalX, goalY);
  que.push(start);
  vector<vector<int>> disMap(h, vector<int>(w, inf));
  disMap[startY][startX] = 0;
  while (!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    int newX, newY;
    for (int dx = -1, dy = 0, i = 0; i < 4;
         dx += dy, dy = dx - dy, dx = dy - dx, ++i) {
      newX = x + dx;
      newY = y + dy;
      if (newX < 0 || newX >= w || newY < 0 || newY >= h ||
          disMap[newY][newX] != inf || mp[newY][newX] == '#')
        continue;
      else if (newX == goal.first && newY == goal.second) {
        if (biggest < disMap[y][x] + 1) {
          biggest = disMap[y][x] + 1;
        }
        return;
      } else {
        disMap[newY][newX] = disMap[y][x] + 1;
        que.push(make_pair(newX, newY));
      }
    }
  }
}
int main() {
  cin >> h >> w;
  if (h == 1 && w == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<vector<char>> theMap(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char num;
      cin >> num;
      theMap[i][j] = num;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          int startX, startY, goalX, goalY;
          startX = j;
          startY = i, goalX = jj;
          goalY = ii;
          wid(startX, startY, goalX, goalY, theMap);
        }
      }
    }
  }
  cout << biggest << endl;
  return 0;
}
