#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
struct edge {
  int myc, to, c, cost;
};
struct pos {
  int to, cost, color;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
vector<pair<int, int> > v[100001];
long long dp2[300000][60] = {};
int main() {
  int h, w;
  cin >> h >> w;
  int d[20][20] = {};
  queue<pair<pair<int, int>, int> > que;
  int r = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char s;
      cin >> s;
      if (s == '#') d[i][j] = 1;
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      que.push(pair<pair<int, int>, int>(pair<int, int>(i, j), 1));
      int dp[20][20] = {};
      int r2 = 0;
      while (!que.empty()) {
        pair<pair<int, int>, int> p = que.front();
        que.pop();
        int x = p.first.first;
        int y = p.first.second;
        int cost = p.second;
        if (cost >= dp[x][y] && dp[x][y] > 0) continue;
        if (d[x][y] > 0) continue;
        dp[x][y] = cost;
        if (x > 0)
          que.push(
              pair<pair<int, int>, int>(pair<int, int>(x - 1, y), cost + 1));
        if (x < h - 1)
          que.push(
              pair<pair<int, int>, int>(pair<int, int>(x - 1, y), cost + 1));
        if (y > 0)
          que.push(
              pair<pair<int, int>, int>(pair<int, int>(x, y - 1), cost + 1));
        if (y < w - 1)
          que.push(
              pair<pair<int, int>, int>(pair<int, int>(x, y + 1), cost + 1));
        r2 = max(r2, cost);
      }
      r = max(r, r2);
    }
  }
  cout << (r - 1) << endl;
  return 0;
}
