#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
struct edge {
  int from;
  int to;
  int weight;
  edge(int f, int t, int w) : from(f), to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
constexpr ll INF = 1e9 + 7;
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
int bfs(pair<int, int> s, pair<int, int> g, const vector<string> &maze) {
  queue<pair<int, int>> que;
  que.push(s);
  int h = maze.size();
  int w = maze[0].size();
  vector<vector<int>> c(h, vector<int>(w, -1));
  c[s.first][s.second] = 0;
  while (!que.empty()) {
    auto t = que.front();
    que.pop();
    int y = t.first, x = t.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && maze[ny][nx] != '#' &&
          c[ny][nx] < 0) {
        que.push(make_pair(ny, nx));
        c[ny][nx] = c[y][x] + 1;
      }
    }
  }
  return c[g.first][g.second];
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)(h); i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++)
      for (int k = 0; k < (int)(h); k++)
        for (int l = 0; l < (int)(w); l++) {
          int result = bfs(make_pair(i, j), make_pair(k, l), s);
          ans = max(ans, result);
        }
  cout << ans << '\n';
}
