#include <bits/stdc++.h>
using namespace std;
const long long inf = LLONG_MAX;
long long ans = 0;
char maze[20][20];
map<pair<long long, long long>, vector<pair<long long, long long> > > neigh;
void bfs(pair<long long, long long> src) {
  queue<pair<long long, long long> > q;
  map<pair<long long, long long>, pair<long long, long long> > parent;
  map<pair<long long, long long>, long long> dist;
  q.push(src);
  dist[src] = 0;
  parent[src] = src;
  while (!q.empty()) {
    pair<long long, long long> node = q.front();
    q.pop();
    vector<pair<long long, long long> > tt = neigh[node];
    for (pair<long long, long long> neighbour : tt) {
      if (dist.find(neighbour) == dist.end()) {
        q.push(neighbour);
        dist[neighbour] = dist[node] + 1;
        ans = max(ans, dist[neighbour]);
      }
    }
  }
}
int main() {
  long long r, c;
  cin >> r >> c;
  for (long long i = 0; i < 20; i++)
    for (long long j = 0; j < 20; j++) maze[i][j] = '#';
  for (long long i = 0; i < r; i++)
    for (long long j = 0; j < c; j++) cin >> maze[i][j];
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      pair<long long, long long> p = make_pair(i, j);
      vector<pair<long long, long long> > ne;
      if (maze[i][j + 1] == '.') ne.push_back(make_pair(i, j + 1));
      if (maze[i][j - 1] == '.') ne.push_back(make_pair(i, j - 1));
      if (maze[i + 1][j] == '.') ne.push_back(make_pair(i + 1, j));
      if (maze[i - 1][j] == '.') ne.push_back(make_pair(i - 1, j));
      neigh[p] = ne;
    }
  }
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      if (maze[i][j] != '#') bfs(make_pair(i, j));
    }
  }
  cout << ans << endl;
}
