#include <bits/stdc++.h>
using namespace std;
static const int INTINF = (2147483647);
static const long long LLINF = (9223372036854775807);
static const int MAX = 1e5 + 1;
static const long long MOD = 1e9 + 7;
namespace Printer {
template <class T>
void print(T x) {
  cout << x << endl;
}
template <class T>
void print(T x, T y) {
  cout << x << "," << y << endl;
}
template <class T>
void print(vector<T> v) {
  for (int i = 0; i < (v.size()); ++i) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
template <class T>
void print(vector<vector<T> > vv) {
  for (int i = 0; i < (vv.size()); ++i) {
    for (int j = 0; j < (vv[i].size()); ++j) {
      if (j) cout << " ";
      cout << vv[i][j];
    }
    cout << endl;
  }
}
void print(pair<int, int> p) {
  cout << "(" << p.first << ", " << p.second << ")" << endl;
}
};  // namespace Printer
using namespace Printer;
vector<string> vv;
int used[21][21];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int solve(int x, int y, int h, int w) {
  for (int i = 0; i < (21); ++i) {
    fill(used[i], used[i] + 21, 0);
  }
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  int cnt = 0;
  used[y][x] = 1;
  while (1) {
    queue<pair<int, int> > q2;
    while (!q.empty()) {
      pair<int, int> f = q.front();
      q.pop();
      int fx = f.first;
      int fy = f.second;
      for (int i = 0; i < (4); ++i) {
        if (fx + dx[i] >= 0 && fx + dx[i] < w && fy + dy[i] >= 0 &&
            fy + dy[i] < h) {
          if (vv[fy + dy[i]][fx + dx[i]] == '.') {
            if (!used[fy + dy[i]][fx + dx[i]]) {
              q2.push(make_pair(fx + dx[i], fy + dy[i]));
              used[fy + dy[i]][fx + dx[i]] = 1;
            }
          }
        }
      }
    }
    q = q2;
    if (q.empty()) {
      break;
    }
    cnt++;
  }
  return cnt;
}
int main(int argc, const char* argv[]) {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) {
    string str;
    cin >> str;
    vv.push_back(str);
  }
  int ans = 0;
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      ans = max(ans, solve(j, i, h, w));
    }
  }
  cout << ans << endl;
  return 0;
}
