#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using i3 = pair<int, ii>;
using li = pair<ll, int>;
using lii = pair<ll, ii>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using vli = vector<li>;
using vpll = vector<pll>;
using vi3 = vector<i3>;
using vlii = vector<lii>;
const int N = 50 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9, PI = acos(-1);
int n, k, m;
char a[N][N];
bool vis[N][N];
int dis[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool inside(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int ans = 0;
void bfs(int x, int y) {
  memset(vis, 0, sizeof vis);
  memset(dis, 0, sizeof dis);
  queue<ii> q;
  q.push({x, y});
  vis[x][y] = 1;
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    ;
    q.pop();
    ans = max(ans, dis[x][y]);
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!inside(nx, ny) || vis[nx][ny]) continue;
      if (a[x][y] == '#') continue;
      vis[nx][ny] = 1;
      dis[nx][ny] = 1 + dis[x][y];
      q.push({nx, ny});
    }
  }
}
void solve(int testCase) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') bfs(i, j);
    }
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int testCase = 1; testCase <= t; testCase++) {
    solve(testCase);
  }
  return 0;
}
