#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> Link;
vector<int> Node;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int H;
  int W;
  queue<pair<int, int>> que;
  cin >> H >> W;
  int S[H][W];
  int flag[H][W];
  int ans[H][W];
  string ttt;
  for (int i = 0; i < H; i++) {
    cin >> ttt;
    for (int j = 0; j < W; j++) {
      S[i][j] = (ttt[j] == '#' ? 1 : 0);
      flag[i][j] = 0;
      ans[i][j] = 0;
    }
  }
  int max = 0;
  int max2 = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      max = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          flag[i][j] = 0;
          ans[i][j] = 0;
        }
      }
      que.push({i, j});
      ans[i][j] = 0;
      flag[i][j] = 1;
      pair<int, int> p;
      while (que.size() > 0) {
        p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int w = p.second + dx[i];
          int h = p.first + dy[i];
          if (0 <= w && w <= W && 0 <= h && h <= H && !flag[h][w] &&
              S[h][w] == 0) {
            flag[h][w] = 1;
            ans[h][w] = ans[p.first][p.second] + 1;
            que.push({h, w});
          }
        }
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          max = (ans[i][j] > max ? ans[i][j] : max);
        }
      }
      max2 = (max2 < max ? max : max2);
    }
  }
  cout << max2 << endl;
}
