#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int M = 2e1 + 5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int n, m;
char s[M][M];
bool vis[M][M];
bool used[M][M];
int mstep;
int D[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct node {
  int x, y, step;
  node(int xx, int yy, int ss) {
    x = xx;
    y = yy;
    step = ss;
  }
  node(){};
} point;
template <class T>
inline void read(T &x) {
  char c;
  x = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') x = -1;
  T res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  x *= res;
}
void bfs(int x, int y) {
  queue<node> q;
  node now(x, y, 0);
  vis[x][y] = 1;
  used[x][y] = 1;
  q.push(now);
  while (q.size()) {
    now = q.front();
    q.pop();
    if (now.step > mstep) {
      mstep = now.step;
      point.x = now.x;
      point.y = now.y;
    }
    for (int i = 0; i <= 3; i++) {
      int xx = now.x + D[i][0];
      int yy = now.y + D[i][1];
      if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && !used[xx][yy] &&
          s[xx][yy] == '.') {
        used[xx][yy] = 1;
        vis[xx][yy] = 1;
        node next(xx, yy, now.step + 1);
        q.push(next);
      }
    }
  }
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s[i][j] = getchar();
    }
    getchar();
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!vis[i][j] && s[i][j] == '.') {
        memset(used, 0, sizeof used);
        mstep = 0;
        bfs(i, j);
        mstep = 0;
        memset(used, 0, sizeof used);
        bfs(point.x, point.y);
        ans = max(ans, mstep);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
