#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
const long long MOD = 1000000007;
struct point {
  int x, y, cost;
};
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    s[i].push_back(s[i][w - 1]);
    s[i].push_back('#');
  }
  for (int i = 0; i < h; i++) {
    for (int j = w; j > 0; j--) {
      s[i][j] = s[i][j - 1];
    }
    s[i][0] = '#';
  }
  s.push_back(s[0]);
  s.push_back(s[0]);
  for (int i = 0; i < w + 2; i++) {
    s[s.size() - 1][i] = '#';
  }
  for (int i = h; i > 0; i--) {
    s[i] = s[i - 1];
  }
  s[0] = s[s.size() - 1];
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#') continue;
      for (int ii = 1; ii <= h; ii++) {
        for (int jj = 1; jj <= w; jj++) {
          vector<vector<bool>> saerched(h + 2, vector<bool>(w + 2, false));
          if (s[ii][jj] == '#') continue;
          queue<point> bfs;
          point p;
          p.y = i;
          p.x = j - 1;
          p.cost = 1;
          bfs.push(p);
          p.x = j + 1;
          bfs.push(p);
          p.y = i - 1;
          p.x = j;
          bfs.push(p);
          p.y = i + 1;
          bfs.push(p);
          while (!bfs.empty()) {
            point pp = bfs.front();
            bfs.pop();
            if (saerched[pp.y][pp.x]) continue;
            if (s[pp.y][pp.x] == '#') continue;
            if (pp.y == ii && pp.x == jj) {
              ans = max(ans, pp.cost);
              break;
            }
            saerched[pp.y][pp.x] = true;
            point tmp;
            tmp.x = pp.x - 1;
            tmp.y = pp.y;
            tmp.cost = pp.cost + 1;
            bfs.push(tmp);
            tmp.x = pp.x + 1;
            bfs.push(tmp);
            tmp.y = pp.y - 1;
            tmp.x = pp.x;
            bfs.push(tmp);
            tmp.y = pp.y + 1;
            bfs.push(tmp);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
