Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque
H,W = map(int,input().split())
field = [list(input()) for _ in range(H)]
dist = [[-1]*W for _ in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
mx = 0
for h in range(H):
    for w in range(W):
        if field[h][w] == "#":
            continue
        dist = [[-1]*W for _ in range(H)]
        dist[h][w] = 0
        que = deque([])
        que.append([h,w])
        while que != deque([]):
            u,v = que.pop()
            for dir in range(4):
                nu = u + dx[dir]
                nv = v + dy[dir]

                if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W):
                    continue
                if field[nu][nv] == "#":
                    continue
                if dist[nu][nv] != -1:
                    if dist[nu][nv] < dist[u][v] + 1:
                        continue
            
                que.append([nu,nv])
                dist[nu][nv] = dist[u][v] + 1
            
            
        for i in range(H):
            for j in range(W):
                if mx < dist[i][j]:
                    mx = dist[i][j]
    
print(mx)

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
field = [list(input()) for _ in range(H)]
dist = [[-1]*W for _ in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
mx = 0
for h in range(H):
    for w in range(W):
        if field[h][w] == "#":
            continue
        dist = [[-1]*W for _ in range(H)]
        dist[h][w] = 0
        que = deque([])
        que.append([h,w])
        while que != deque([]):
            u,v = que.popleft()
            for dir in range(4):
                nu = u + dx[dir]
                nv = v + dy[dir]

                if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W):
                    continue
                if field[nu][nv] == "#":
                    continue
                if dist[nu][nv] != -1:
                    continue
            
                que.append([nu,nv])
                dist[nu][nv] = dist[u][v] + 1
            
            
        for i in range(H):
            for j in range(W):
                if mx < dist[i][j]:
                    mx = dist[i][j]
    
print(mx)
### BUGGY CODE ###

n = int(input())
li = list(map(int, input().split()))
ans_li = [0] * n
for i in range(1, n+1):
    ans_li[i-1] = (li.index(i)+1)
print(*ans_li)

### FIXED CODE ###

n = int(input())
li = list(map(int, input().split()))
ans_li = [0] * n
for i in range(n):
    ans_li[li[i]-1] = i+1
print(*ans_li)
### BUGGY CODE ###

N = input()
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if (k%2 == 0 and q[1] == '1') or (k%2 == 1 and q[1] == '2'):
            N = q[2] + N
        else:
            N = N + q[2]

if k%2==1:
    ans = ''.join(list(reversed(N)))
    print(ans)
else:
    print(N)


### FIXED CODE ###

from collections import deque

N = deque(input())
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if k%2 ==0:
            if q[1]=='1':
                N.appendleft(q[2])
            else:
                N.append(q[2])
        else:
            if q[1]=='2':
                N.appendleft(q[2])
            else:
                N.append(q[2])
if k%2==1:
    ans=''
    for x in reversed(N):
        ans += x
else:
    ans=''
    for x in N:
        ans += x

print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(M)]
good = (list(range(N)))

for i in range(M):
  if H[l[i][0]-1] != H[l[i][1]-1]:
    Hmin = min(H[l[i][0]-1], H[l[i][1]-1])
    Hindex = H.index(Hmin)
    good = list(set(good) - set([Hindex]))
  else:
    AB = [l[i][0]-1, l[i][1]-1]
    good = list(set(good) - set(AB))

print(len(good))

### FIXED CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))
g = [0] * N
r = [0] * N
for i in range(M):
  a, b = list(map(int, input().split()))
  if H[a-1] > H[b-1]:
    g[a-1] += 1
  if H[a-1] < H[b-1]:
    g[b-1] += 1
  r[a-1] += 1
  r[b-1] += 1

ans = 0
for j in range(N):
  if g[j] == r[j]:
    ans += 1
print(ans)
### BUGGY CODE ###

import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    test = a.pop(-1)
    bisect.insort(a, test // 2)
print(sum(a))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [-a[i] for i in range(n)]
heapq.heapify(a)
for i in range(m):
    test = heapq.heappop(a)
    heapq.heappush(a, -(-test // 2))
print(-sum(a))
### BUGGY CODE ###

def doqueri(S,N,L,R):
	s = S[L-1:R]
	l = [0] * (L-1)
	r = [0] * (N-R)

	return l+s+r

if __name__ == '__main__':
	N, M = map(int, input().split())
	S = [1] * N
	for _ in range(M):
		L,R = map(int, input().split())
		S = doqueri(S[:],N,L,R)
	print(S.count(1))

### FIXED CODE ###

if __name__ == '__main__':
	N, M = map(int, input().split())
	lmax = 0
	rmin = N
	for _ in range(M):
		L,R = map(int, input().split())
		if L > lmax:
			lmax = L
		if R < rmin:
			rmin = R
	ans = rmin - lmax + 1
	if ans < 0:
		ans = 0

	print(ans)
### BUGGY CODE ###

x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
if(x > 54 & y > 54 & z > 54):
	ax = a[0] - a[54]
	bx = b[0] - b[54]
	cx = c[0] - c[54]
	for n in range(x):
		if(a[0] - a[n] > bx + cx):
			x = n
			break;
	for n in range(y):
		if(b[0] - b[n] > ax + cx):
			y = n
			break;
	for n in range(z):
		if(c[0] - c[n] > bx + ax):
			z = n
			break;
for ka in range(x):
    for kb in range(y):
		for kc in range(z):
			s.append(a[ka]+b[kb]+c[kc])
s.sort(reverse = True)
for n in range(k):
	print(s[n])

### FIXED CODE ###

x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
for ka in range(x):
    for kb in range(y):
			s.append(a[ka]+b[kb])
s.sort(reverse = True)
p = 3000
if(x * y < 3000):
	p = x * y
t = []
for n in range(p):
	for m in c:
		t.append(s[n] + m)
t.sort(reverse = True)
for n in range(k):
	print(t[n])
### BUGGY CODE ###

def solve() :
  N,M,Q = raw_input().split()
  N = int(N)
  M = int(M)
  Q = int(Q)
  
  grid = []
  for i in range(N):
    raw = raw_input()
    grid.append(raw)
  qs = []
  for ii in range(Q):
    raw = raw_input()
    qs.append(raw)

  for q in qs:
    qq = q.split()
    #print 'q=',q
    y1 = int(qq[0]) - 1
    x1 = int(qq[1]) - 1
    y2 = int(qq[2]) - 1
    x2 = int(qq[3]) - 1
    w = x2 - x1 + 1
    h = y2 - y1 + 1

    mapp = [[0 for col in range(w)] for row in range(h)]
    eqs = 0
    next = 1
    for y in range(h):
      for x in range(w):
        c = grid[y+y1][x+x1]
        if c == '0': continue
        up = -1 if y == 0 else mapp[y-1][x]
        left = -1 if x == 0 else mapp[y][x-1]
        #print 'y=',y,'x=',x,'up=',up,',left=',left
        if up > 0:
          if left > 0:
            if up == left : mapp[y][x] = up
            else :
              #print 'eq! :up=',up,',left=',left
              eqs += 1
              mapp[y][x] = left
          else :
            mapp[y][x] = up
        else:
          if left > 0:
            mapp[y][x] = left
          else: 
            mapp[y][x] = next
            next += 1
        #print 'up=',up,',left=',left,',mapp[',y,'][',x,']=',mapp[y][x]
    #print 'mapp=',mapp

    #sett = set()
    #for y in range(h) :
    #  for x in range(w) :
    #    #print 'y,x=',y,x
    #    if(mapp[y][x] > 0):  sett.add(mapp[y][x])
    #print 'sett=',sett,',eqs=',eqs
    print next-1-eqs

if __name__ == '__main__' :
  solve()

### FIXED CODE ###

N,M,Q = map(int,input().split())
src = [input() for i in range(N)]
qs = [tuple(map(int,input().split())) for i in range(Q)]

blue_cum = [[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N):
    for j in range(M):
        blue_cum[i+1][j+1] += blue_cum[i+1][j] + int(src[i][j])
for i in range(N):
    for j in range(M+1):
        blue_cum[i+1][j] += blue_cum[i][j]

h_edge = [[0 for j in range(M)] for i in range(N+1)]
for i in range(N):
    for j in range(M-1):
        h_edge[i+1][j+1] += h_edge[i+1][j] + int(src[i][j:j+2]=='11')
for i in range(N):
    for j in range(M):
        h_edge[i+1][j] += h_edge[i][j]

v_edge = [[0 for j in range(M+1)] for i in range(N)]
for i in range(N-1):
    for j in range(M):
        v_edge[i+1][j+1] += v_edge[i+1][j] + int(src[i][j]=='1' and src[i+1][j]=='1')
for i in range(N-1):
    for j in range(M+1):
        v_edge[i+1][j] += v_edge[i][j]

ans = []
for y1,x1,y2,x2 in qs:
    y1 -= 1
    x1 -= 1
    blue = blue_cum[y1][x1] - blue_cum[y1][x2] - blue_cum[y2][x1] + blue_cum[y2][x2]
    edge = h_edge[y1][x1] - h_edge[y1][x2-1] - h_edge[y2][x1] + h_edge[y2][x2-1]
    edge+= v_edge[y1][x1] - v_edge[y1][x2] - v_edge[y2-1][x1] + v_edge[y2-1][x2]
    ans.append(blue - edge)
print(*ans, sep='\n')
### BUGGY CODE ###

import bisect
n=int(input())
l=list(map(int,input().split()))
l_2=[]
for i in range(1,n+1):
    l_2.append(l.index(i)+1)
s=''
for j in range(n):
    s+=str(l_2[j])+' '
print(s)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l2=[0]*(n+1)
for i,j in enumerate(l,1):
    l2[j]=i 
print(' '.join(map(str,l2[1:])))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
a = line_to_list()

from functools import reduce, partial
from operator import mul

prod = partial(reduce, mul)

if 0 in a:
    print(0)
else:
    if prod(a) <= 10**18:
        print(prod(a))
    else:
        print(-1)
# ans = a[0]
# if 0 in a:
#     print(0)
# else:
#     for i in range(1,n):
#         ans = ans * a[i]
#     if ans <= 10**18:
#         print(ans)
#     else:
#         print(-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
a = line_to_list()

# from functools import reduce, partial
# from operator import mul

# prod = partial(reduce, mul)

# if 0 in a:
#     print(0)
# else:
#     if prod(a) <= 10**18:
#         print(prod(a))
#     else:
#         print(-1)
ans = a[0]
limit = 10**18
if 0 in a:
    print(0)
else:
    for i in range(1,n):
        if ans <= limit:
            ans = ans * a[i]
        else:
            print(-1)
            exit()
    if ans <= limit:
        print(ans)
    else:
        print(-1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int,input().split())

neighbor = {}
for i in range(1,n+1):
    neighbor[i] = []

for i in range(n-1):
    x, y = map(int,input().split())
    neighbor[x].append(y)
    neighbor[y].append(x)

dp = [[-1] * (n+1) for _ in range(n+1)]

def calc_dp(x, y):
    if(dp[x][y] != -1):
        return(dp[x][y])

    if(len(neighbor[y]) == 1):
        dp[x][y] = 2 % m
        return(dp[x][y])

    temp = 1
    for i in neighbor[y]:
        if(i == x):
            continue

        temp = temp * (calc_dp(y,i)) % m

    temp = (temp + 1) % m
    dp[x][y] = temp
    return(temp)

for i in range(1,n+1):
    ans = 1
    for j in neighbor[i]:
        ans = ans * calc_dp(i,j) % m
    print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
mod = m
# mod = 10**9+7

# 前準備
import sys
input = sys.stdin.readline
from collections import deque

graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ini = 1

def calc(a,b):
    p = a * b % mod
    return p

# calc1 の定義
def calc1(c,p):
    p_num = ini
    for i in graph[c]:
        if i == p:
            continue
        p_num = calc(p_num, dp1[i])
    p_num += 1
    dp1[c] = p_num % mod

# calc2 の定義
def calc2(p):
    arr = [dp1[c] if c != parent[p] else dp2[p] for c in graph[p]]

    left = [ini]
    for i in arr[:-1]:
        left.append( calc(left[-1], i ) )
    right = [ini]
    for i in arr[:0:-1]:
        right.append( calc(right[-1], i) )
    right = right[::-1]

    prod = []
    for a,b in zip(left,right):
        prod.append(calc(a,b))

    for c,x in zip(graph[p], prod):
        if(c != parent[p]):
            dp2[c] = (x + 1)%mod



# 根から探索して親と探索順を記録
root = 1
order = []
parent = [0] * (n+1)
stack = deque()
stack.append(root)
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        stack.append(y)
        parent[y] = x

# 親→子の値を算出
dp1 = [None] * (n+1)
for i in order[::-1]:
    calc1(i, parent[i])

# 子→親の値を算出　累積和チックにすることでうに対策。
dp2 = [None] * (n+1)
dp2[root] = ini
for i in order:
    calc2(i)

for i in range(1,n+1):
    ans = calc(dp1[i]-1, dp2[i])
    print(ans)
### BUGGY CODE ###

import re

def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

x=arr_data[0][0]


pattern="ST"


cnt=10**10000
for i in range(cnt):
    
    if "ST" in x:

        x = re.sub(pattern, "", x)
    else:
        
        break
        
print(len(x))

### FIXED CODE ###

from collections import deque
def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

x=arr_data[0][0]

b = deque([])

for v in x:
    
    if v=="S":
        
        b.appendleft(v)
        
    elif v=="T" and (len(b)==0 or b[0]=="T"):
        
        b.appendleft(v)
        
    else:
            
        b.popleft()
            
print(len(b))
### BUGGY CODE ###

import sys

k = int(input())

a = 0

for i in range(1, k+1):
  a = a*10+7
  if a%k == 0:
      print(i)
      sys.exit()
print(-1)


### FIXED CODE ###

import sys

k = int(input())

a = 0

for i in range(1, k+1):
  a = (a*10+7)%k
  if a == 0:
      print(i)
      sys.exit()

print(-1)
### BUGGY CODE ###

n = int(input())
li = [int(x) for x in input().split()]

sub = list()
for i in li:
    if i in sub:
        print("NO")
        break
    sub.append(i)
else:
    print("YES")

### FIXED CODE ###

n = int(input())
li = [int(x) for x in input().split()]

nozoki = list(set(li))
nozoki.sort()
li.sort()
if (nozoki == li):
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
lisA = list(map(int,input().split()))

lisA.sort()

needcheck = set()
divable = set()
for i in range(N):
    if i == 0:
        needcheck.add(lisA[i])
        continue
    else:
        for num in needcheck:
            if lisA[i] % num == 0:
                divable.add(lisA[i])
                break
        else:
            needcheck.add(lisA[i])

ans = needcheck - divable
print(len(ans))
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

import numpy as np
from numba import njit
  
# @njit('(i4[::1],)', cache=True)
def solve(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        if count[x] > 1:
            continue
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret

N = int(input())
A = np.array(list(map(int,input().split())), np.int32)
 
print(solve(A))
### BUGGY CODE ###

S = str(input())


def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
solution(S)


### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

from collections import deque, defaultdict

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]

canBattle = defaultdict(lambda: False)
D = [0] * N

while True:
    isChanged = False
    for i, a in enumerate(A):
        if not a:
            continue
        j = a[0]
        canBattle[(i, j)] = True

        if canBattle[(j, i)]:
            isChanged = True
            A[i].popleft()
            A[j].popleft()
            d = max(D[i], D[j])
            D[i], D[j] = d + 1, d + 1
    if all(len(a) == 0 for a in A):
        print(max(D))
        exit()
    if not isChanged:
        break

print(-1)


### FIXED CODE ###

import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')


def sol():
    N = int(input())
    A = [deque()] + [deque(map(int, input().split())) for _ in range(N)]

    days = [0] * (N + 1)
    now = [0] * (N + 1)

    que = deque([i + 1 for i in range(N)])

    while que:
        i = que.popleft()
        if not A[i]:
            continue

        a = A[i].popleft()
        if now[a] == i:
            days[a] = days[i] = max(days[a], days[i]) + 1
            que.append(i)
            que.append(a)
            now[a] = now[i] = 0
        else:
            now[i] = a

    for i in range(1, N + 1):
        if A[i]:
            print(-1)
            return
    print(max(days))


sol()
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]

f = True
day = 1
while(f):
  done = set()
  nokori_games = 0
  
  for m in range(n):
    la = len(a[m])
    nokori_games += la
    if m in done:
      pass
    elif la:
      teki = a[m][0]
      jibun = m + 1
      if not len(a[teki - 1]):
        print(-1)
        sys.exit()
      elif a[teki - 1][0] == jibun and teki - 1 not in done:
        a[m].popleft()
        a[teki - 1].popleft()
        done.add(m)
        done.add(teki - 1)
        nokori_games -= 1
  if not nokori_games:
    print(day)
    sys.exit()
  else:
    if not len(done):
      print(-1)
      sys.exit()
  day += 1


### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

H,W = map(int,input().split())
A = []

for i in range(H):
    t = list(input())
    A.append(t)

tate = (-1,1,0,0)
yoko = (0,0,-1,1)
answer = 0

def move(i,j):
    for p, q in zip(tate, yoko):
        m = i + p
        n = j + q
        if m >= 0 and m < H:
            if n >= 0 and n < W:
                if A[m][n] == '.':
                    if dp[m][n] > dp[i][j]+1:
                        dp[m][n] = dp[i][j] + 1
                        move(m,n)

for i in range(H):
    for j in range(W):
        dp = [[10**4 for i in range(W)] for j in range(H)]
        if A[i][j] == '.':
            dp[i][j] = 0
            move(i,j)
            for k in range(H):
                for l in range(W):
                    if dp[k][l] < 10**4:
                        answer = max(answer,dp[k][l])

print(answer)

### FIXED CODE ###

H,W = map(int,input().split())
A = []

for i in range(H):
    t = list(input())
    A.append(t)

tate = (-1,1,0,0)
yoko = (0,0,-1,1)
answer = 0

for i in range(H):
    for j in range(W):
        dp = [[10**4 for i in range(W)] for j in range(H)]
        if A[i][j] == '.':
            dp[i][j] = 0
            Q = list()
            Q.append([i,j])
            while(len(Q) > 0 ):
                s = Q[0][0]
                t = Q[0][1]
                for p, q in zip(tate, yoko):
                    m = s + p
                    n = t + q
                    if m >= 0 and m < H:
                        if n >= 0 and n < W:
                            if A[m][n] == '.':
                                if dp[m][n] == 10**4 :
                                    dp[m][n] = dp[s][t] + 1
                                    Q.append([m,n])
                Q.remove(Q[0])

            for k in range(H):
                for l in range(W):
                    if dp[k][l] < 10**4:
                        answer = max(answer,dp[k][l])

print(answer)