#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long L = 40;
long long grid[L][L];
long long vis[L][L];
long long h, w;
pair<long long, long long> src, trg;
struct node {
  long long x, y, dist;
};
long long bfs() {
  deque<node> q;
  node temp;
  temp.x = src.first;
  temp.y = src.second;
  temp.dist = 1;
  q.push_front(temp);
  while (!q.empty()) {
    node p = q.front();
    q.pop_front();
    long long i;
    vis[p.x][p.y] = 1;
    vector<node> vec;
    node p1 = p;
    p1.x -= 1;
    node p2 = p;
    p2.x += 1;
    node p3 = p;
    p3.y -= 1;
    node p4 = p;
    p4.y += 1;
    vec.push_back(p1);
    vec.push_back(p2);
    vec.push_back(p3);
    vec.push_back(p4);
    for (long long i = 0; i < 4; i++) {
      if (vec[i].x == trg.first && vec[i].y == trg.second) {
        return vec[i].dist;
      }
      if (vec[i].x < 0 || vec[i].y < 0 || vec[i].x >= w || vec[i].y >= h) {
        continue;
      }
      if (vis[vec[i].x][vec[i].y] == 1 || grid[vec[i].x][vec[i].y] == 0)
        continue;
      vec[i].dist += 1;
      q.push_back(vec[i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> h >> w;
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < w; j++) {
      if (s[j] == '.') {
        grid[j][i] = 1;
      }
    }
  }
  for (long long x1 = 0; x1 < w; x1++) {
    for (long long y1 = 0; y1 < h; y1++) {
      for (long long x2 = 0; x2 < w; x2++) {
        for (long long y2 = 0; y2 < h; y2++) {
          if (grid[x1][y1] == 1 && grid[x2][y2] == 1 &&
              !(x1 == x2 && y1 == y2)) {
            for (long long i = 0; i < w; i++) {
              for (long long j = 0; j < h; j++) {
                vis[i][j] = 0;
              }
            }
            src = {x1, y1};
            trg = {x2, y2};
            long long pos = bfs();
            ans = max(ans, pos);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
