#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
void vout(vector<long long> &v) {
  for (long long i = 0; i < (v).size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void vout(vector<string> &v) {
  for (long long i = 0; i < (v).size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void vvout(vector<vector<long long> > &v) {
  for (long long i = 0; i < (v).size(); i++) vout(v[i]);
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long mypow(long long x, long long n, long long m) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return mypow(x * x % m, n / 2, m);
  else
    return x * mypow(x, n - 1, m) % m;
}
long long digit(long long k, long long i) {
  string s = to_string(k);
  return s[s.size() - i] - '0';
}
void uniq(vector<long long> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
long long leng(long long n) {
  string s = to_string(n);
  return s.size();
}
long long lesscount(long long x, vector<long long> &a) {
  return lower_bound(a.begin(), a.end(), x) - a.begin();
}
long long orlesscount(long long x, vector<long long> &a) {
  return upper_bound(a.begin(), a.end(), x) - a.begin();
}
long long morecount(long long x, vector<long long> &a) {
  return a.size() - orlesscount(x, a);
}
long long ormorecount(long long x, vector<long long> &a) {
  return a.size() - lesscount(x, a);
}
long long count(long long x, vector<long long> &a) {
  return upper_bound((a).begin(), (a).end(), x) -
         lower_bound((a).begin(), (a).end(), x);
}
vector<long long> accum(vector<long long> &v) {
  vector<long long> ret((v).size() + 1);
  for (long long i = 0; i < (v).size(); ++i) ret[i + 1] = ret[i] + v[i];
  return ret;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
struct field {
  long long H, W;
  vector<string> F;
  vector<vector<long long> > dist;
  const vector<long long> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
  field(long long h, long long w, vector<string> s) { init(h, w, s); }
  void init(long long h, long long w, vector<string> s) {
    H = h;
    W = w;
    F = s;
    dist.resize(H);
    for (long long i = 0; i < H; ++i) dist[i].resize(W);
    for (long long i = 0; i < H; ++i) {
      for (long long j = 0; j < W; ++j) {
        dist[i][j] = LLONG_MAX / 2;
      }
    }
  }
  void update(long long h, long long w, char c) { F[h][w] = c; }
  bool inside(long long h, long long w) {
    return (0 <= h && h < H && 0 <= w && w < W);
  }
  long long bfs(long long sh, long long sw, long long gh, long long gw) {
    for (long long i = 0; i < H; ++i) {
      for (long long j = 0; j < W; ++j) {
        dist[i][j] = 0;
      }
    }
    dist[sh][sw] = 0;
    queue<pair<long long, long long> > q;
    q.push(make_pair(sh, sw));
    while (!q.empty()) {
      long long nowh, noww;
      tie(nowh, noww) = q.front();
      q.pop();
      for (long long d = 0; d < dx.size(); ++d) {
        long long newh = nowh + dx[d], neww = noww + dy[d];
        if (inside(newh, neww) && dist[newh][neww] == 0) {
          if (newh == gh && neww == gw) return dist[nowh][noww] + 1;
          if (F[newh][neww] == '.') {
            dist[newh][neww] = dist[nowh][noww] + 1;
            q.push(make_pair(newh, neww));
          }
        }
      }
    }
    return -1;
  }
  void zigzag(long long sh, long long sw) {
    for (long long i = 0; i < H; ++i) {
      for (long long j = 0; j < W; ++j) {
        dist[i][j] = 0;
      }
    }
    long long h = sh, w = sw;
    for (long long i = 0; i < H * W; ++i) {
      long long newh = h, neww = w;
      if (h % 2 == 0) {
        if (neww == W - 1)
          ++newh;
        else
          ++neww;
      } else {
        if (neww == 0)
          ++newh;
        else
          --neww;
      }
      h = newh;
      w = neww;
    }
  }
  long long size() {
    long long ret = 0;
    for (long long i = 0; i < H; ++i) {
      for (long long j = 0; j < W; ++j) {
        if (dist[i][j] > 0) ret++;
      }
    }
    return ret;
  }
};
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  long long h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0; i < h; ++i) cin >> s[i];
  field F(h, w, s);
  long long ans = 0;
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      for (long long k = 0; k < h; ++k) {
        for (long long l = 0; l < w; ++l) {
          chmax(ans, F.bfs(i, j, k, l));
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
