#include <bits/stdc++.h>
#pragma target("avx")
using namespace std;
constexpr long long INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr long long LINF = 1e18;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[30][30];
long long n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (long long(i) = 0; (i) < (int)(h); (i)++)
    for (long long(j) = 0; (j) < (int)(w); (j)++) cin >> s[i][j];
  for (long long(i) = 0; (i) < (int)(h); (i)++) {
    for (long long(j) = 0; (j) < (int)(w); (j)++) {
      long long min_cost[h + 10][w + 10];
      for (long long(ii) = 0; (ii) < (int)(h); (ii)++)
        for (long long(jj) = 0; (jj) < (int)(w); (jj)++)
          min_cost[ii][jj] = LINF;
      queue<pair<long long, long long> > qu;
      qu.push({i, j});
      min_cost[i][j] = 0;
      while (!qu.empty()) {
        auto p = qu.front();
        qu.pop();
        for (long long(z) = 0; (z) < (int)(4); (z)++) {
          int nx = p.second + dx[z], ny = p.first + dy[z];
          if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
          if (s[ny][nx] == '#') continue;
          if (min_cost[p.first][p.second] + 1 >= min_cost[ny][nx]) continue;
          min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
          qu.push({ny, nx});
        }
      }
      cnt = 0;
      for (long long(ii) = 0; (ii) < (int)(h); (ii)++) {
        for (long long(jj) = 0; (jj) < (int)(w); (jj)++) {
          if (min_cost[ii][jj] == LINF) continue;
          cnt = max(cnt, min_cost[ii][jj]);
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << (ans) << endl;
  return 0;
}
