#include <bits/stdc++.h>
using namespace std;
int H, W, ans = 0;
char MP[22][22];
void bfs(int sx, int sy, int gx, int gy) {
  bool color[22][22] = {{0}};
  queue<pair<int, int>> Q;
  queue<int> C;
  Q.push(make_pair(sx, sy));
  C.push(0);
  color[sx][sy] = 1;
  while (!Q.empty()) {
    pair<int, int> p = Q.front();
    int c = C.front();
    Q.pop();
    C.pop();
    if (p.first == gx && p.second == gy) {
      ans = max(ans, c);
      break;
    }
    if (!color[p.first - 1][p.second] && MP[p.first - 1][p.second] != '#') {
      Q.push(make_pair(p.first - 1, p.second));
      C.push(c + 1);
      color[p.first - 1][p.second] = 1;
    }
    if (!color[p.first + 1][p.second] && MP[p.first + 1][p.second] != '#') {
      Q.push(make_pair(p.first + 1, p.second));
      C.push(c + 1);
      color[p.first + 1][p.second] = 1;
    }
    if (!color[p.first][p.second - 1] && MP[p.first][p.second - 1] != '#') {
      Q.push(make_pair(p.first, p.second - 1));
      C.push(c + 1);
      color[p.first][p.second - 1] = 1;
    }
    if (!color[p.first][p.second + 1] && MP[p.first][p.second + 1] != '#') {
      Q.push(make_pair(p.first, p.second + 1));
      C.push(c + 1);
      color[p.first][p.second + 1] = 1;
    }
  }
}
void bfsinit() {
  for (int i1 = 1; i1 <= H; i1++) {
    for (int j1 = 1; j1 <= W; j1++) {
      for (int i2 = 1; i2 <= H; i2++) {
        for (int j2 = 1; j2 <= W; j2++) {
          bfs(j1, i1, j2, i2);
        }
      }
    }
  }
}
signed main() {
  cin >> H >> W;
  for (int i = 0; i < 22; i++) {
    for (int j = 0; j < 22; j++) {
      MP[i][j] = '#';
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) cin >> MP[j][i];
  }
  bfsinit();
  cout << ans << endl;
  return 0;
}
