#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 2147483647;
const long long int LLINF = 9223372036854775807;
struct xy {
  int x;
  int y;
  int d;
};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  queue<xy> q;
  int ans = 0;
  vector<vector<bool>> used(h, vector<bool>(w, false));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#' || used[i][j])
        continue;
      else {
        vector<vector<bool>> f(h, vector<bool>(w, false));
        int dmax = 0, xmax, ymax;
        q.push({i, j});
        while (!q.empty()) {
          int x = q.front().x;
          int y = q.front().y;
          int d = q.front().d;
          q.pop();
          f[x][y] = true;
          if (d > dmax) {
            dmax = d;
            xmax = x;
            ymax = y;
          }
          ans = max(ans, d);
          if (x != 0) {
            if (s[x - 1][y] == '.' && !f[x - 1][y]) q.push({x - 1, y, d + 1});
          }
          if (x != h - 1) {
            if (s[x + 1][y] == '.' && !f[x + 1][y]) q.push({x + 1, y, d + 1});
          }
          if (y != 0) {
            if (s[x][y - 1] == '.' && !f[x][y - 1]) q.push({x, y - 1, d + 1});
          }
          if (y != w - 1) {
            if (s[x][y + 1] == '.' && !f[x][y + 1]) q.push({x, y + 1, d + 1});
          }
        }
        for (int k = 0; k < h; k++)
          for (int l = 0; l < w; l++) f[k][l] = false;
        q.push({xmax, ymax});
        while (!q.empty()) {
          int x = q.front().x;
          int y = q.front().y;
          int d = q.front().d;
          q.pop();
          f[x][y] = true;
          used[x][y] = true;
          ans = max(ans, d);
          if (x != 0) {
            if (s[x - 1][y] == '.' && !f[x - 1][y]) q.push({x - 1, y, d + 1});
          }
          if (x != h - 1) {
            if (s[x + 1][y] == '.' && !f[x + 1][y]) q.push({x + 1, y, d + 1});
          }
          if (y != 0) {
            if (s[x][y - 1] == '.' && !f[x][y - 1]) q.push({x, y - 1, d + 1});
          }
          if (y != w - 1) {
            if (s[x][y + 1] == '.' && !f[x][y + 1]) q.push({x, y + 1, d + 1});
          }
        }
      }
    }
  cout << ans;
}
