#include <bits/stdc++.h>
using namespace std;
int h, w;
int d[100][100];
int color[100][100];
int col[100][100];
typedef struct {
  int s;
  int t;
} num;
void bfs(int x, int y) {
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      color[i][j] = col[i][j];
    }
  }
  queue<num> q;
  num p;
  p.s = x;
  p.t = y;
  q.push(p);
  d[x][y] = 0;
  num u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    if (u.s - 1 > 0 && color[u.s - 1][u.t] == 0) {
      num p2;
      p2.s = u.s - 1;
      p2.t = u.t;
      d[u.s - 1][u.t] = d[u.s][u.t] + 1;
      color[u.s - 1][u.t] = 1;
      q.push(p2);
    }
    if (u.s + 1 <= h && color[u.s + 1][u.t] == 0) {
      num p2;
      p2.s = u.s + 1;
      p2.t = u.t;
      d[u.s + 1][u.t] = d[u.s][u.t] + 1;
      color[u.s + 1][u.t] = 1;
      q.push(p2);
    }
    if (u.t - 1 > 0 && color[u.s][u.t - 1] == 0) {
      num p2;
      p2.s = u.s;
      p2.t = u.t - 1;
      d[u.s][u.t - 1] = d[u.s][u.t] + 1;
      color[u.s][u.t - 1] = 1;
      q.push(p2);
    }
    if (u.t + 1 <= w && color[u.s][u.t + 1] == 0) {
      num p2;
      p2.s = u.s;
      p2.t = u.t + 1;
      d[u.s][u.t + 1] = d[u.s][u.t] + 1;
      color[u.s][u.t + 1] = 1;
      q.push(p2);
    }
  }
}
int main() {
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      col[i][j] = 1;
    }
  }
  cin >> h >> w;
  int sx, sy, gx, gy;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char a;
      cin >> a;
      if (a == '.') {
        col[i][j] = 0;
      }
    }
  }
  int maxnum = 0;
  for (sx = 1; sx <= h; sx++) {
    for (sy = 1; sy <= w; sy++) {
      if (col[sx][sy] == 0) bfs(sx, sy);
      for (gx = 1; gx <= h; gx++) {
        for (gy = 1; gy <= w; gy++) {
          if (maxnum < d[gx][gy]) maxnum = d[gx][gy];
        }
      }
    }
  }
  cout << maxnum << endl;
}
