#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int long long
using P = pair<int, int>;
using PP = pair<P, int>;
#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
int H, W;
bool g[20][20];
bool visited[20][20];
void ResetVisited() {
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      visited[h][w] = false;
    }
  }
}
int GetDistance(int start_y, int start_x) {
  if(!g[start_y][start_x]) return 0;
  int ret = 0;
  queue<PP> q;
  PP qt = PP(P(start_y, start_x),0);
  visited[start_y][start_x] = true;
  q.push(qt);
  while(!q.empty()) {
    qt = q.front();
    int curr_x = qt.first.second;
    int curr_y = qt.first.first;
    int curr_d = qt.second;
    q.pop();
    for(int dy = -1; dy <= 1; ++dy) {
      for(int dx = -1; dx <= 1; ++dx) {
        if(!dy && !dx) continue;  // 自分の位置
        if(abs(dy)+abs(dx) == 2) continue; // 斜め移動

        int next_x = curr_x + dx;
        int next_y = curr_y + dy;
        int next_d = curr_d + 1;

        // 範囲外
        if(next_x < 0 || next_x >= W) continue;
        if(next_y < 0 || next_y >= H) continue;

        // 通れないまたはすでに到達済み
        if(!g[next_y][next_x]) continue;
        if(visited[next_y][next_x]) continue;
        ret = max(ret, next_d);
        q.push(PP(P(next_y,next_x),next_d));
        visited[next_y][next_x] = true;
      }
    }
  }
  return ret;
}
signed main() {
  cin >> H >> W;
  REP(i,H) {
    REP(j,W) {
      char c;
      cin >> c;
      g[i][j] = (c == '.');
    }
  }
  int ans = 0;
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      ans = max(ans, GetDistance(h, w));
      ResetVisited();
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256