#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};
struct pos {
  int x, y, sx, sy, cost;
};
long long dp[21][21][21][21] = {};
char c[21][21] = {};
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> c[j][i];
    }
  }
  queue<pos> que;
  long long total = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (c[j][i] == '.') {
        if (c[j + 1][i] == '.') {
          pos pos1 = {j + 1, i, j, i, 1};
          que.push(pos1);
        }
        if (c[j - 1][i] == '.') {
          pos pos2 = {j - 1, i, j, i, 1};
          que.push(pos2);
        }
        if (c[j][i + 1] == '.') {
          pos pos8 = {j, i + 1, j, i, 1};
          que.push(pos8);
        }
        if (c[j][i - 1] == '.') {
          pos pos9 = {j, i - 1, j, i, 1};
          que.push(pos9);
        }
        while (!que.empty()) {
          pos pos3 = que.front();
          que.pop();
          dp[pos3.sx][pos3.sy][pos3.x][pos3.y] = pos3.cost;
          total = max(total, dp[pos3.sx][pos3.sy][pos3.x][pos3.y]);
          if (c[pos3.x + 1][pos3.y] == '.' &&
              dp[pos3.sx][pos3.sy][pos3.x + 1][pos3.y] == 0) {
            pos pos4 = {pos3.x + 1, pos3.y, pos3.sx, pos3.sy, pos3.cost + 1};
            que.push(pos4);
          }
          if (c[pos3.x][pos3.y + 1] == '.' &&
              dp[pos3.sx][pos3.sy][pos3.x][pos3.y + 1] == 0) {
            pos pos5 = {pos3.x, pos3.y + 1, pos3.sx, pos3.sy, pos3.cost + 1};
            que.push(pos5);
          }
          if (c[pos3.x - 1][pos3.y] == '.' &&
              dp[pos3.sx][pos3.sy][pos3.x - 1][pos3.y] == 0) {
            pos pos6 = {pos3.x - 1, pos3.y, pos3.sx, pos3.sy, pos3.cost + 1};
            que.push(pos6);
          }
          if (c[pos3.x][pos3.y - 1] == '.' &&
              dp[pos3.sx][pos3.sy][pos3.x][pos3.y - 1] == 0) {
            pos pos7 = {pos3.x, pos3.y - 1, pos3.sx, pos3.sy, pos3.cost + 1};
            que.push(pos7);
          }
        }
      }
    }
  }
  cout << total << endl;
  return 0;
}
