#include <bits/stdc++.h>
using namespace std;
int h, w, d1 = 0, vx, vy, d2 = 0, vx2, vy2;
vector<vector<bool>> vis1(21, vector<bool>(21, true)),
    vis2(21, vector<bool>(21, true));
vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool isValid(int a, int b) { return a >= 0 && a < h && b >= 0 && b < w; }
void dfs1(int x, int y, int &d, vector<vector<bool>> &vis) {
  vis[x][y] = true;
  queue<pair<pair<int, int>, int>> q;
  q.push(make_pair(make_pair(x, y), 0));
  while (!q.empty()) {
    auto nd = q.front();
    q.pop();
    if (nd.second > d) {
      d = nd.second;
      vx = nd.first.first;
      vy = nd.first.second;
    }
    for (int i = 0; i < dir.size(); i++) {
      int tx = nd.first.first + dir[i][0], ty = nd.first.second + dir[i][1];
      if (isValid(tx, ty) && vis[tx][ty] == false) {
        vis[tx][ty] = true;
        q.push(make_pair(make_pair(tx, ty), nd.second + 1));
      }
    }
  }
}
int main() {
  cin >> h >> w;
  vector<vector<char>> maze(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> maze[i][j];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (maze[i][j] == '.') vis1[i][j] = vis2[i][j] = false;
  bool bb = true;
  for (int i = 0; i < h && bb; i++)
    for (int j = 0; j < w; j++)
      if (maze[i][j] == '.') {
        dfs1(i, j, d1, vis1);
        dfs1(vx, vy, d2, vis2);
        bb = false;
        break;
      }
  cout << d2 << endl;
  return 0;
}
