#include <bits/stdc++.h>
using namespace std;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int solve(const vector<string>& board, int h, int w, int sy, int sx, int gy,
          int gx) {
  vector<vector<int>> cost(h + 2, vector<int>(w + 2, 1e9));
  queue<pair<int, int>> que;
  que.push(make_pair(sy, sx));
  cost[sy][sx] = 0;
  while (not que.empty()) {
    int y = que.front().first, x = que.front().second;
    que.pop();
    for (int k = 0; k < (4); k++) {
      int ny = y + dy[k], nx = x + dx[k];
      if (board[ny][nx] == '#') continue;
      if (cost[ny][nx] != 1e9) continue;
      que.push(make_pair(ny, nx));
      cost[ny][nx] = min(cost[ny][nx], cost[y][x] + 1);
    }
  }
  return cost[gy][gx] == 1e9 ? 0 : cost[gy][gx];
}
int main(int argc, char const* argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 2);
  string b;
  for (int i = 0; i < (w + 2); i++) b += '#';
  s[0] = b;
  for (int i = 0; i < (h); i++) {
    string t;
    cin >> t;
    t = '#' + t + '#';
    s[i + 1] = t;
  }
  s[h + 1] = b;
  for (int i = 0; i < (h + 2); i++) cout << s[i] << endl;
  int ans = 0;
  for (int sy = 0; sy < (h); sy++)
    for (int sx = 0; sx < (w); sx++)
      for (int gy = 0; gy < (h); gy++)
        for (int gx = 0; gx < (w); gx++) {
          if (s[sy + 1][sx + 1] == '#' or s[gy + 1][gx + 1] == '#') continue;
          int cost = solve(s, h, w, sy + 1, sx + 1, gy + 1, gx + 1);
          ans = max(ans, cost);
        }
  cout << ans << endl;
  return 0;
}
