#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX = 510000;
const long long MOD = 1000000007;
int h, w;
char maze[20][20];
long long x, y;
long long d[20][20][20][20];
long long dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  cin >> h >> w;
  for (long long i = (0); i < (h); ++i) {
    for (long long j = (0); j < (w); ++j) {
      cin >> maze[i][j];
    }
  }
  long long ans = 0;
  for (long long sy = (0); sy < (h); ++sy) {
    for (long long sx = (0); sx < (w); ++sx) {
      queue<pair<long long, long long> > que;
      for (long long i = (0); i < (h); ++i) {
        for (long long j = (0); j < (w); ++j) {
          d[sy][sx][i][j] = 100000;
        }
      }
      d[sy][sx][sy][sx] = 0;
      que.push(pair<long long, long long>(sy, sx));
      while (que.size()) {
        pair<long long, long long> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int ny = p.first + dy[i];
          int nx = p.second + dx[i];
          if (nx >= 0 && nx < w && ny >= 0 && ny < h &&
              d[sy][sx][ny][nx] == 100000 && maze[ny][nx] != '#') {
            d[sy][sx][ny][nx] = d[sy][sx][p.first][p.second] + 1;
            que.push(pair<long long, long long>(ny, nx));
          }
        }
      }
      long long tmp = 0;
      for (long long i = (0); i < (h); ++i) {
        for (long long j = (0); j < (w); ++j) {
          if (d[sy][sx][i][j] == 100000) continue;
          tmp = max(tmp, d[sy][sx][i][j]);
        }
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}
