#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LLINF = 1LL << 60;
const int INF = 1 << 30;
class UnionFind {
 public:
  vector<int> rank;
  vector<int> p;
  UnionFind() {}
  UnionFind(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) {
      makeSet(i);
    }
  };
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
  bool isSame(int x, int y) { return findSet(x) == findSet(y); }
  void unite(int x, int y) { link(findSet(x), findSet(y)); }

 private:
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
};
const int MOD_NUM = 2;
class RollingHash {
  vector<long long> hash[MOD_NUM];
  vector<long long> mod = {999999937LL, 1000000007LL};
  long long base = 9973;

 public:
  RollingHash(string s) { initialize(s); }
  vector<long long> getHashNum(int left, int right) {
    vector<long long> res(MOD_NUM);
    for (int i = 0; i < MOD_NUM; i++) {
      res[i] = ((hash[i][right] -
                 hash[i][left] * this->mpower(base, right - left, mod[i])) %
                    mod[i] +
                mod[i]) %
               mod[i];
    }
    return res;
  }

 private:
  void initialize(string s) {
    for (int i = 0; i < MOD_NUM; i++) {
      hash[i].assign(s.size() + 1, 0);
      for (int j = 0; j < s.size(); j++) {
        hash[i][j + 1] = (hash[i][j] * base + s[j]) % mod[i];
      }
    }
  }
  long long mpower(long long x, long long n, long long mod) {
    if (n == 0) {
      return 1;
    } else if (n % 2 == 0) {
      return mpower(x * x % mod, n / 2, mod);
    } else {
      return x * mpower(x, n - 1, mod) % mod;
    }
  }
};
template <class T>
inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}
template <class T>
inline T gcd(T x, T y) {
  if (y == 0) {
    return x;
  } else if (x == 0) {
    return y;
  }
  return gcd(y, x % y);
}
template <class T>
inline T lcm(T x, T y) {
  return x / gcd(x, y) * y;
}
template <class T>
inline void print_vector(vector<T> vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
template <class T>
inline T mpower(T x, T n) {
  if (n == 0) {
    return 1;
  } else if (n % 2 == 0) {
    return mpower(x * x % MOD, n / 2);
  } else {
    return x * mpower(x, n - 1) % MOD;
  }
}
long long mfrac(long long x) {
  long long res = 1;
  for (long long i = x; i >= 1; i--) {
    res *= i;
    res %= MOD;
  }
  return res;
}
long long mcomb(long long n, long long r) {
  if (n == 0 and r == 0) {
    return 1;
  } else if (n < r || n < 0) {
    return 0;
  }
  long long res = mfrac(n) * mpower(mfrac(r), MOD - 2) % MOD;
  res *= mpower(mfrac(n - r), MOD - 2) % MOD;
  return res;
}
vector<long long> make_divisor(long long x) {
  vector<long long> res;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res.push_back(i);
      if (i * i != x) {
        res.push_back(x / i);
      }
    }
  }
  return res;
}
template <class T>
vector<T> eratosthenes(T x) {
  vector<T> is_prime_number(x + 1, 1);
  is_prime_number[0] = 0;
  is_prime_number[1] = 0;
  for (T i = 2; i * i <= x; i++) {
    for (T j = 2; i * j <= x; j++) {
      is_prime_number[i * j] = 0;
    }
  }
  vector<T> prime_numbers;
  for (T i = 0; i < is_prime_number.size(); i++) {
    if (is_prime_number[i]) {
      prime_numbers.push_back(i);
    }
  }
  return prime_numbers;
}
const int MAX = 45;
vector<vector<int>> dp(MAX, vector<int>(MAX, INF));
void warshall_floyd(int n) {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      if (dp[i][k] == INF) continue;
      for (int j = 1; j <= n; j++) {
        if (dp[k][j] == INF) continue;
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H + 2, vector<char>(W + 2));
  for (int y = 1; y <= H; y++) {
    string L;
    cin >> L;
    for (int x = 1; x <= W; x++) {
      grid[y][x] = L[x - 1];
    }
  }
  for (int y = 1; y <= H; y++) {
    for (int x = 1; x <= W; x++) {
      int current_node = W * (y - 1) + x;
      dp[current_node][current_node] = 0;
      if (grid[y - 1][x] == '.') {
        dp[current_node][current_node - W] = 1;
      }
      if (grid[y + 1][x] == '.') {
        dp[current_node][current_node + W] = 1;
      }
      if (grid[y][x - 1] == '.') {
        dp[current_node][current_node - 1] = 1;
      }
      if (grid[y][x + 1] == '.') {
        dp[current_node][current_node + 1] = 1;
      }
    }
  }
  warshall_floyd(H * W);
  int ans = 0;
  for (int i = 0; i < H * W + 2; i++) {
    for (int j = 0; j < H * W + 2; j++) {
      if (dp[i][j] == INF)
        continue;
      else
        chmax(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
