#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H;
int W;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
struct Point {
  int h, w;
  Point(int h, int w) {
    this->h = h;
    this->w = w;
  }
  Point() {
    this->h = 0;
    this->w = 0;
  }
};
struct Dis {
  int d;
  Point p;
  Dis(int d, Point p) {
    this->d = d;
    this->p = p;
  }
};
string Maze[20];
vector<Point> SG;
void solve() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> Maze[i];
    for (int j = 0; j < W; ++j) {
      if (Maze[i][j] == '.') {
        SG.push_back(Point(i, j));
      }
    }
  }
  int L = SG.size();
  int max_l = 0;
  for (int i = 0; i < L; ++i) {
    Point s = SG[i];
    queue<Dis> q;
    q.push(Dis(0, s));
    int me[H][W];
    memset(me, -1, sizeof(me));
    while (!q.empty()) {
      Dis dis = q.front();
      q.pop();
      me[dis.p.h][dis.p.w] = 1;
      if (max_l < dis.d) {
        max_l = dis.d;
      }
      for (int k = 0; k < 4; ++k) {
        int nh = dis.p.h + dx[k];
        int nw = dis.p.w + dy[k];
        if (!(nh >= 0 && nh < H && nw >= 0 && nw < W)) continue;
        if (me[nh][nw] != -1) continue;
        if (Maze[nh][nw] != '.') continue;
        q.push(Dis(dis.d + 1, Point(nh, nw)));
      }
    }
  }
  cout << max_l << endl;
}
int main() {
  solve();
  return 0;
}
