#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


template <typename Cost = int> class Edge{
public:
  int from,to;
  Cost cost;
  Edge() {}
  Edge(int to, Cost cost): to(to), cost(cost){}
  Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){}

  Edge rev() const {return Edge(to,from,cost);}
  
  friend std::ostream& operator<<(std::ostream &os, const Edge &e){
    os << "(FROM: " << e.from << "," << "TO: " << e.to << "," << "COST: " << e.cost << ")";
    return os;
  }
};

template <typename T> using Graph = std::vector<std::vector<Edge<T>>>;
template <typename T> using Tree = std::vector<std::vector<Edge<T>>>;

template <typename C, typename T> void add_edge(C &g, int from, int to, T w){
  g[from].push_back(Edge<T>(from, to, w));  
}

template <typename C, typename T> void add_undirected(C &g, int a, int b, T w){
  g[a].push_back(Edge<T>(a, b, w));
  g[b].push_back(Edge<T>(b, a, w));
}

template <typename T>
class Unbounded{
  enum class Tag { Value, PositiveInfinity, NegativeInfinity } tag;
  T val;
  
public:
  Unbounded(Tag tag): tag(tag){}
  Unbounded(const T &val): tag(Tag::Value), val(val){}

  auto& operator=(const T &rhs){
    this->tag = Tag::Value;
    this->val = rhs;
    return *this;
  }
  
  static auto pos_inf(){return Unbounded(Tag::PositiveInfinity);}
  static auto neg_inf(){return Unbounded(Tag::NegativeInfinity);}
  static auto value(const T &a){return Unbounded(a);}
  inline bool is_pos_inf() const {return tag == Tag::PositiveInfinity;}
  inline bool is_neg_inf() const {return tag == Tag::NegativeInfinity;}
  inline bool is_value() const {return tag == Tag::Value;}
  const T& get_value(){return this->val;}

  inline bool operator==(const Unbounded &rhs) const {
    if(this->tag == rhs.tag){
      if(this->tag == Tag::Value) return this->val == rhs.val;
      else return true;
    }
    return false;
  }

  friend std::ostream& operator<<(std::ostream &os, const Unbounded &rhs){
    switch(rhs.tag){
    case Tag::Value: os << rhs.val; break;
    case Tag::PositiveInfinity: os << "INF"; break;
    case Tag::NegativeInfinity: os << "-INF"; break;
    }
    return os;
  }
};

template <typename T>
struct WarshallFloyd{
  using Result = Unbounded<T>;
  
  int n;
  std::vector<std::vector<Result>> dist;
  bool has_negative_cycle;
  
  WarshallFloyd(const Graph<T> &graph):
    n(graph.size()), dist(n, std::vector<Result>(n, Result::pos_inf())), has_negative_cycle(false)
  {

    for(int i = 0; i < n; ++i){
      dist[i][i] = 0;
    }
    
    for(int i = 0; i < n; ++i){
      for(auto &e : graph[i]){
        dist[e.from][e.to] = e.cost;
      }
    }

    for(int k = 0; k < n; ++k){
      for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
          if(not dist[i][k].is_pos_inf() and not dist[k][j].is_pos_inf()){
            if(dist[i][j].is_pos_inf()){
              dist[i][j] = dist[i][k].get_value() + dist[k][j].get_value();
            }else{
              dist[i][j] = std::min(dist[i][j].get_value(), dist[i][k].get_value() + dist[k][j].get_value());
            }
          }
        }
      }
    }
    
    for(int i = 0; i < n; ++i) if(dist[i][i].get_value() < 0) has_negative_cycle = true;
  }
};










struct Point{
  int x, y;
  Point(): x(0), y(0){}
  Point(int x, int y): x(x), y(y){}
  Point& operator+=(const Point &a){this->x += a.x; this->y += a.y; return *this;}
  Point& operator-=(const Point &a){this->x -= a.x; this->y -= a.y; return *this;}
};

Point operator+(const Point &a, const Point &b){return Point(a.x+b.x, a.y+b.y);}
Point operator-(const Point &a, const Point &b){return Point(a.x-b.x, a.y-b.y);}
bool operator==(const Point &a, const Point &b){return a.x == b.x and a.y == b.y;}
bool operator!=(const Point &a, const Point &b){return !(a == b);}

std::ostream& operator<<(std::ostream &os, const Point &a){
  os << "(" << a.x << "," << a.y << ")";
  return os;
}

namespace grid{
  const std::vector<Point> dir4 = {Point(0,1), Point(0,-1), Point(1,0), Point(-1,0)};
  const std::vector<Point> dir8 = {Point(-1,-1), Point(-1,0), Point(-1,1), Point(1,-1), Point(1,0), Point(1,1), Point(0,-1), Point(0,1)};
}


template <typename T, typename Checker, typename Generator>
Graph<T> grid_to_graph(int H, int W,
                       const std::vector<Point> &dir,
                       const Checker &check_passable,
                       const std::vector<std::vector<int>> &index,
                       const Generator &generate_edge_cost)
{
  Graph<T> ret(H * W);

  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      auto p = Point(i, j);

      for(auto &d : dir){
        auto q = Point(i, j) + d;

        if(q.x < 0 or q.x >= H or q.y < 0 or q.y >= W or not check_passable(p, q)) continue;

        auto e = Edge<T>(index[p.x][p.y], index[q.x][q.y], generate_edge_cost(p, q));
        
        ret[index[p.x][p.y]].emplace_back(e);
      }
    }
  }
  
  return ret;
}





int main(){
  int H,W;
  while(cin >> H >> W){
    vector<string> S(H); cin >> S;

    int ans = 0;

    auto index = vector<vector<int>>(H, vector<int>(W));
    {
      int k = 0;
      REP(i,H) REP(j,W) index[i][j] = k++;
    }
    auto g = grid_to_graph<int>(H, W,
                                grid::dir4,
                                [&](const auto &p, const auto &q){return S[p.x][p.y] == '.' and S[q.x][q.y] == '.';},
                                index,
                                [&](const auto &p, const auto &q){return 1;});
    
    auto res = WarshallFloyd<int>(g).dist;

    REP(i,H*W){
      REP(j,H*W){
        if(res[i][j].is_value()) chmax(ans, res[i][j].get_value());
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1536