#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int maze[w + 2][h + 2];
  int mazed[w + 2][h + 2];
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      maze[j][i] = 0;
    }
  }
  int sx, sy;
  sx = 1;
  sy = 1;
  int d[w + 2][h + 2];
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      d[j][i] = 0;
    }
  }
  string s;
  int black = 0;
  for (int i = 1; i <= h; i++) {
    cin >> s;
    for (int j = 1; j <= w; j++) {
      if (s[j - 1] == '.') {
        maze[j][i] = 1;
      } else {
        black++;
      }
    }
  }
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      mazed[j][i] = maze[j][i];
    }
  }
  int max = 0;
  for (int i = 0; i < h * w; i++) {
    int sx = i % w + 1;
    int sy = i / w + 1;
    for (int l = 0; l < h + 2; l++) {
      for (int j = 0; j < w + 2; j++) {
        maze[j][l] = mazed[j][l];
      }
    }
    queue<pair<int, int> > q;
    pair<int, int> p;
    pair<int, int> p_nx;
    p.first = sx;
    p.second = sy;
    q.push(p);
    d[sx][sy] = 0;
    maze[sx][sy] = 0;
    while (!q.empty()) {
      p = q.front();
      q.pop();
      p_nx.first = p.first;
      p_nx.second = p.second - 1;
      if (maze[p_nx.first][p_nx.second] == 1) {
        q.push(p_nx);
        d[p_nx.first][p_nx.second] = d[p.first][p.second] + 1;
        maze[p_nx.first][p_nx.second] = 0;
      }
      p_nx.first = p.first;
      p_nx.second = p.second + 1;
      if (maze[p_nx.first][p_nx.second] == 1) {
        q.push(p_nx);
        d[p_nx.first][p_nx.second] = d[p.first][p.second] + 1;
        maze[p_nx.first][p_nx.second] = 0;
      }
      p_nx.first = p.first - 1;
      p_nx.second = p.second;
      if (maze[p_nx.first][p_nx.second] == 1) {
        q.push(p_nx);
        d[p_nx.first][p_nx.second] = d[p.first][p.second] + 1;
        maze[p_nx.first][p_nx.second] = 0;
      }
      p_nx.first = p.first + 1;
      p_nx.second = p.second;
      if (maze[p_nx.first][p_nx.second] == 1) {
        q.push(p_nx);
        d[p_nx.first][p_nx.second] = d[p.first][p.second] + 1;
        maze[p_nx.first][p_nx.second] = 0;
      }
    }
    for (int j = 0; j < h * w; j++) {
      if (d[j % w + 1][j / w + 1] > max) {
        max = d[j % w + 1][j / w + 1];
      }
    }
  }
  cout << max << endl;
  return 0;
}
