#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
  cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
  cin >> x >> y >> z >> w;
}
template <typename T, typename T0>
void read(pair<T, T0> &p) {
  cin >> p.fst >> p.scd;
}
template <typename T>
void read(vector<T> &oneD, long long int n) {
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    long long int x;
    read(x);
    oneD.push_back(x);
  }
}
template <typename T>
void read(T oneD[], long long int n) {
  for (long long int i = 0; i < n; i++) {
    read(oneD[i]);
  }
}
template <typename T>
void write(T &x) {
  cout << x << " ";
}
template <typename T, typename T0>
void write(T &x, T0 &y) {
  cout << x << " " << y << "\n";
}
template <typename T, typename T0, typename T1>
void write(T &x, T0 &y, T1 &z) {
  cout << x << " " << y << " " << z << "\n";
}
template <typename T, typename T0, typename T1, typename T2>
void write(T &x, T0 &y, T1 &z, T2 &w) {
  cout << x << " " << y << " " << z << " " << w << "\n";
}
template <typename T, typename T0>
void write(pair<T, T0> &p) {
  write(p.fst);
  write(p.scd);
  cout << endl;
}
template <typename T>
void write(vector<T> &oneD, long long int n) {
  for (long long int i = 0; i < n; i++) {
    cout << oneD[i] << " ";
  }
  cout << endl;
}
template <typename T>
void write(T oneD[], int n) {
  for (long long int i = 0; i < n; i++) {
    write(oneD[i]);
  }
  cout << endl;
}
template <typename T, typename T0>
void write(map<T, T0> &mpp) {
  for (auto it : mpp) {
    write(it.fst);
    cout << ": ";
    write(it.scd);
    cout << "\n";
  }
  cout << endl;
}
vector<long long int> seive;
void Seive() {
  const long long int maxn = 1000005;
  seive.resize(maxn);
  for (long long int(i) = 0; (i) < (maxn); ++(i)) seive[i] = i;
  for (long long int(i) = 2; (i) <= (maxn); (i) += (2)) seive[i] = 2;
  seive[1] = -1;
  seive[0] = -1;
  for (long long int i = 3; i <= maxn; i += 2)
    if (i == seive[i])
      for (long long int j = i * i; j < maxn; j += i)
        if (seive[j] == j) seive[j] = i;
}
long long int extended_GCD(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long int modinv(long long int a, long long int mod = 1000000007) {
  long long int x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
long long int find_x_CRT(long long int num[], long long int rem[],
                         long long int n) {
  long long int pro = 1;
  for (long long int(i) = 0; (i) < (n); ++(i)) pro *= num[i];
  long long int res = 0;
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    long long int pp = pro / num[i];
    res += (rem[i] * modinv(pp, num[i]) * pp);
  }
  res %= pro;
  return res;
}
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int powe(long long int a, long long int b,
                   long long int m = 1000000007) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
string getString(char x) {
  string s(1, x);
  return s;
}
void update(vector<long long int> &BIT, long long int index,
            long long int inc) {
  while (index <= BIT.size()) {
    BIT[index] += inc;
    index += (index & (-index));
  }
}
long long int query(vector<long long int> &BIT, long long int index) {
  long long int sum = 0;
  while (index > 0) {
    sum += BIT[index];
    index -= (index & (-index));
  }
  return sum;
}
void make_set(long long int v, vector<long long int> &parent,
              vector<long long int> &siz) {
  parent[v] = v;
  siz[v] = 1;
}
long long int find_set(long long int x, vector<long long int> &parent) {
  if (x == parent[x])
    return x;
  else {
    return parent[x] = find_set(parent[x], parent);
  }
}
void union_set(long long int a, long long int b, vector<long long int> &siz,
               vector<long long int> &parent) {
  a = find_set(a, parent);
  b = find_set(b, parent);
  if (a != b) {
    if (siz[a] < siz[b]) swap(a, b);
    parent[b] = a;
    siz[a] += siz[b];
    siz[b] = 0;
  }
}
long long int diameter(long long int st, long long int en,
                       vector<vector<char>> ad, long long int n,
                       long long int m) {
  vector<vector<long long int>> level(n);
  vector<vector<bool>> vis(n);
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    for (long long int(j) = 0; (j) < (m); ++(j)) {
      level[i].push_back(0);
      vis[i].push_back(false);
    }
  }
  queue<pair<long long int, long long int>> q;
  q.push({st, en});
  vis[st][en] = true;
  while (!q.empty()) {
    pair<long long int, long long int> z = q.front();
    long long int r = z.first;
    long long int c = z.second;
    q.pop();
    if (r >= 1 && !vis[r - 1][c] && ad[r - 1][c] != '#') {
      q.push({r - 1, c});
      vis[r - 1][c] = true;
      level[r - 1][c] = level[r][c] + 1;
    }
    if (c >= 1 && !vis[r][c - 1] && ad[r][c - 1] != '#') {
      q.push({r, c - 1});
      vis[r][c - 1] = true;
      level[r][c - 1] = level[r][c] + 1;
    }
    if ((r + 1) < n && !vis[r + 1][c] && ad[r + 1][c] != '#') {
      q.push({(r + 1), c});
      vis[r + 1][c] = true;
      level[r + 1][c] = level[r][c] + 1;
    }
    if ((c + 1) < n && !vis[r][c + 1] && ad[r][c + 1] != '#') {
      q.push({r, c + 1});
      vis[r][c + 1] = true;
      level[r][c + 1] = level[r][c] + 1;
    }
  }
  long long int ma = 0, ind_i = 0, ind_j = 0;
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    for (long long int(j) = 0; (j) < (m); ++(j)) {
      ma = max(ma, level[i][j]);
    }
  }
  return ma;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  read(n, m);
  vector<vector<char>> ad(n);
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    string s;
    read(s);
    for (long long int(j) = 0; (j) < (m); ++(j)) {
      ad[i].push_back(s[j]);
    }
  }
  long long int ans = 0;
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    for (long long int(j) = 0; (j) < (m); ++(j)) {
      if (ad[i][j] == '.') {
        long long int y = diameter(i, j, ad, n, m);
        ans = max(ans, y);
      }
    }
  }
  cout << ans;
  return 0;
}
