#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, w;
  cin >> h >> w;
  vector<vector<char>> a(h + 2, vector<char>(w + 2, 'e'));
  for (long long i = 1; i <= h; i++)
    for (long long j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  long long ans = 0;
  for (long long i = 1; i <= h; i++) {
    for (long long j = 1; j <= w; j++) {
      for (long long y = 1; y <= h; y++) {
        for (long long x = 1; x <= w; x++) {
          vector<vector<long long>> dist(h + 2, vector<long long>(w + 2, -1));
          queue<pair<long long, long long>> que;
          long long sy = i;
          long long sx = j;
          long long gy = y;
          long long gx = x;
          dist[sy][sx] = 0;
          que.push({sy, sx});
          const long long dy[4] = {1, 0, -1, 0};
          const long long dx[4] = {0, 1, 0, -1};
          while (!que.empty()) {
            pair<long long, long long> p = que.front();
            que.pop();
            for (long long i = 0; i < 4; i++) {
              long long y_next = p.first + dy[i];
              long long x_next = p.second + dx[i];
              if (dist[y_next][x_next] != -1) continue;
              if (a[y_next][x_next] == 'e' || a[y_next][x_next] == '#')
                continue;
              dist[y_next][x_next] = dist[p.first][p.second] + 1;
              que.push({y_next, x_next});
            }
          }
          ans = max(ans, dist[gy][gx]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
