#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  err(++it, args...);
}
int ini() {
  int x;
  scanf("%d", &x);
  return x;
}
long long inl() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double ind() {
  double x;
  scanf("%lf", &x);
  return x;
}
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = (int)1e6 + 5;
const int M = (int)1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
string s[N];
bool vis[25][25];
int dis[25][25];
int h, w;
int res = 0;
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (xx >= 0 and xx < h and yy >= 0 and yy < w and !vis[xx][yy] and
        s[xx][yy] != '#') {
      dis[xx][yy] = dis[x][y] + 1;
      res = max(res, dis[xx][yy]);
      dfs(xx, yy);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1, te = 0;
  while (t--) {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        for (int ii = 0; ii < h; ++ii) {
          for (int jj = 0; jj < w; ++jj) {
            vis[ii][jj] = false;
            dis[ii][jj] = 0;
          }
        }
        if (s[i][j] != '#') {
          dfs(i, j);
        }
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
