#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MAX = 1000000007;
vector<string> string_list;
long long maze[20][20];
long long h, w;
void init() {
  for (long long i = 0; i < h; i++) {
    string s = string_list[i];
    for (long long j = 0; j < s.size(); j++) {
      maze[j][i] = (s[j] == '#') ? -1 : MAX;
    }
  }
}
long long run(pair<long long, long long> start) {
  stack<pair<long long, long long>> s;
  maze[start.first][start.second] = 0;
  s.push(start);
  for (;;) {
    if (s.size() == 0) {
      break;
    }
    auto cur = s.top();
    s.pop();
    long long x = cur.first;
    long long y = cur.second;
    long long next = maze[x][y] + 1;
    if (x >= 1) {
      if (maze[x - 1][y] != -1 && maze[x - 1][y] > next) {
        maze[x - 1][y] = next;
        s.push(make_pair(x - 1, y));
      }
    }
    if (x < w - 1) {
      if (maze[x + 1][y] != -1 && maze[x + 1][y] > next) {
        maze[x + 1][y] = next;
        s.push(make_pair(x + 1, y));
      }
    }
    if (y >= 1) {
      if (maze[x][y - 1] != -1 && maze[x][y - 1] > next) {
        maze[x][y - 1] = next;
        s.push(make_pair(x, y - 1));
      }
    }
    if (y < h - 1) {
      if (maze[x][y + 1] != -1 && maze[x][y + 1] > next) {
        maze[x][y + 1] = next;
        s.push(make_pair(x, y + 1));
      }
    }
  }
  long long result = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      result = max(result, maze[j][i]);
    }
  }
  return result;
}
int main() {
  scanf("%lld %lld", &h, &w);
  for (long long i = 0; i < h; i++) {
    string s;
    cin >> s;
    string_list.emplace_back(s);
  }
  long long ans = 0;
  for (long long i = 0; i < w; i++) {
    for (long long j = 0; j < h; j++) {
      init();
      auto start = make_pair(i, j);
      long long a = run(start);
      ans = max(ans, a);
    }
  }
  cout << ans << endl;
}
