#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int max = 0;
  vector<string> maze(h);
  for (int i = 0; i < h; i++) {
    cin >> maze[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '#') {
        continue;
      } else {
        vector<vector<int>> cnt(h, vector<int>(w, 100));
        queue<pair<int, int>> q;
        q.push(make_pair(i, j));
        cnt[i][j] = 0;
        while (!q.empty()) {
          int x = q.front().first;
          int y = q.front().second;
          q.pop();
          if (x > 0) {
            if (cnt[x - 1][y] > cnt[x][y] + 1 && maze[x - 1][y] != '#') {
              cnt[x - 1][y] = cnt[x][y] + 1;
              q.push(make_pair(x - 1, y));
            }
          }
          if (x < h - 1) {
            if (cnt[x + 1][y] > cnt[x][y] + 1 && maze[x + 1][y] != '#') {
              cnt[x + 1][y] = cnt[x][y] + 1;
              q.push(make_pair(x + 1, y));
            }
          }
          if (y > 0) {
            if (cnt[x][y - 1] > cnt[x][y] + 1 && maze[x][y - 1] != '#') {
              cnt[x][y - 1] = cnt[x][y] + 1;
              q.push(make_pair(x, y - 1));
            }
          }
          if (y < w - 1) {
            if (cnt[x][y + 1] > cnt[x][y] + 1 && maze[x][y + 1] != '#') {
              cnt[x][y + 1] = cnt[x][y] + 1;
              q.push(make_pair(x, y + 1));
            }
          }
        }
        for (int x = 0; x < h; x++) {
          for (int y = 0; y < w; y++) {
            if (cnt[x][y] != 100 && max < cnt[x][y]) {
              max = cnt[x][y];
            }
          }
        }
      }
    }
  }
  std::cout << max << endl;
}
