#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
int H, W;
vector<string> maze;
vector<vector<bool>> done;
vector<vector<int32_t>> dis;
void dfs(int sy, int sx) {
  queue<pair<int, int>> q;
  done[sy][sx] = true;
  q.push(make_pair(sx, sy));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j) dis[i][j] = 1e9;
  dis[sy][sx] = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    if (x > 0 && !done[y][x - 1] && maze[y][x - 1] == '.') {
      dis[y][x - 1] = ((dis[y][x - 1]) > (dis[y][x] + 1) ? (dis[y][x] + 1)
                                                         : (dis[y][x - 1]));
      done[y][x - 1] = true;
      q.push(make_pair(x - 1, y));
    }
    if (x < W - 1 && !done[y][x + 1] && maze[y][x + 1] == '.') {
      dis[y][x + 1] = ((dis[y][x + 1]) > (dis[y][x] + 1) ? (dis[y][x] + 1)
                                                         : (dis[y][x + 1]));
      done[y][x + 1] = true;
      q.push(make_pair(x + 1, y));
    }
    if (y > 0 && !done[y - 1][x] && maze[y - 1][x] == '.') {
      dis[y - 1][x] = ((dis[y - 1][x]) > (dis[y][x] + 1) ? (dis[y][x] + 1)
                                                         : (dis[y - 1][x]));
      done[y - 1][x] = true;
      q.push(make_pair(x, y - 1));
    }
    if (y < H - 1 && !done[y + 1][x] && maze[y + 1][x] == '.') {
      dis[y + 1][x] = ((dis[y + 1][x]) > (dis[y][x] + 1) ? (dis[y][x] + 1)
                                                         : (dis[y + 1][x]));
      done[y + 1][x] = true;
      q.push(make_pair(x, y + 1));
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  maze.resize(H);
  done.resize(H, vector<bool>(W, false));
  dis.resize(H, vector<int32_t>(W));
  for (int i = 0; i < H; ++i) cin >> maze[i];
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
          done[y][x] = false;
        }
      }
      dfs(i, j);
      for (int k = 0; k < H; ++k) {
        for (int l = 0; l < W; ++l) {
          if (dis[k][l] == 1e9) continue;
          ans = ((ans) < (dis[k][l]) ? (dis[k][l]) : (ans));
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
