Harryxun/stf_run huggingface dataset:
import sys

sys.setrecursionlimit(10000)


def cheaperprice(item):
    rawprice=rawprices[item]
    if item not in menus:
        return rawprice
    else:
        indegrients=menus[item]
        combinedprice=0
        for i in indegrients:
            combinedprice+=cheaperprice(i)
        return min(combinedprice,rawprice)


n=0 #how many numbers of lists
flag=0
rawprices={}
menus={}

for line in sys.stdin:
    line=line.strip()
    if n==0:
        if flag==0 and line=='0':
            break
        elif flag!=2:
            n=int(line)
        else:
            print cheaperprice(line)
            rawprices={}
            menus={}
        flag=(flag+1)%3
    else:
        line=line.split(' ')
        if flag==1: #rawprices
            rawprices[line[0]]=int(line[1])
        elif flag==2:
            menus[line[0]]=line[2:]
        n-=1

### FIXED CODE ###

while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        pricelist=[]
        recipedict={}
        costdict={}
        for i in range(n):
            [ii,p]=raw_input().split()
            pricelist.append([ii,int(p)])
            costdict[ii]=1000000000000
        pricelist.sort(key=lambda x:x[1])
        m=int(raw_input())
        for i in range(m):
            rec=raw_input().split()
            o=rec[0]
            k=int(rec[1])
            recipedict[o]=rec[2:]
        query=raw_input()
        while(1):
            cheapest=pricelist.pop(0)
            #if able to make
            if cheapest[0] in recipedict:
                priceifmade=0
                for reqitem in recipedict[cheapest[0]]:
                    priceifmade=priceifmade+costdict[reqitem]
                if priceifmade<cheapest[1]:
                    costdict[cheapest[0]]=priceifmade
                else:
                    costdict[cheapest[0]]=cheapest[1]
            else:
                costdict[cheapest[0]]=cheapest[1]
            for item in recipedict:
                priceifmade=0
                for reqitem in recipedict[item]:
                    priceifmade=priceifmade+costdict[reqitem]
                if priceifmade<costdict[item]:
                    costdict[item]=priceifmade
            if cheapest[0]==query:
                print costdict[cheapest[0]]
                break
from collections import deque
n = int(input())
dll = deque()

for i in range(n):
    input_line = [str(s) for s in input().split()]
    if input_line[0] == "insert":
        dll.appendleft(int(input_line[1]))
    elif input_line[0] == "delete":
        dll.remove(int(input_line[1]))
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
print(*dll)

### FIXED CODE ###

from collections import deque
   
n = int(input())
dll = deque()
   
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
           
print(*dll)
from collections import deque

S = deque(input())
queryNum = input()
flip = False
for i in range(int(queryNum)):
	order = input()
	if order == '1':
		if flip:
			flip = False
		else:
			flip = True
	else:
		if order[2] == '1':
			if not flip:
				S.appendleft(order[4])
			elif flip:
				S.appendright(order[4])
		else:
			if not flip:
				S.appendright(order[4])
			elif flip:
				S.appendleft(order[4])
S = ''.join(S)
if flip:
	print(S[::-1])
else: 
	print(S)

### FIXED CODE ###

from collections import deque

S = deque(input())
queryNum = input()
flip = False
for i in range(int(queryNum)):
	order = input()
	if order == '1':
		if flip:
			flip = False
		else:
			flip = True
	else:
		if order[2] == '1':
			if not flip:
				S.appendleft(order[4])
			elif flip:
				S.append(order[4])
		else:
			if not flip:
				S.append(order[4])
			elif flip:
				S.appendleft(order[4])
S = ''.join(S)
if flip:
	print(S[::-1])
else: 
	print(S)
print("ai1333"+"3"*"int(input())//100))


### FIXED CODE ###

print("ai1333"+"3"*(int(input())//100))
A , B = input ( ).split ( ' ' )
print ( int ( A ) * int ( B ) , end = " " )
print ( 2 * ( int ( A ) + int ( B ) ) )

### FIXED CODE ###

A , B = map ( int , raw_input ( ).split ( ) )
print A*B , 2* ( A + B )
import math
target = int(input())
curAns = target

for i in range(0,int(math.sqrt(target))):
  if target % i == 0:
    j = target // i
    if (i+j-2) < curAns:
      curAns = i+j-2
print(curAns)

### FIXED CODE ###

n=int(input())
ans=n
for i in range(int(n**0.5),0,-1):
    if n%i==0:
        ans=n//i+i-2
        break
print(ans)
X,K,D=map(int, input().split())
X=abs(X)
if X-K*D>0:
  print(X-K*D)
else:
  if K%2==0:
    s=X-2*D*int(X/(2*D))
    t=-(s-2*D)
    if s<t:
      print(s)
    else:
      print(t)
  else:
    s=X-2*D*int((X-D)/(2*D))+D
    t=-(s-2*D)
    r=s-2D
    print(min(s,t,r))


### FIXED CODE ###

X,K,D=map(int, input().split())
X=abs(X)
if X-K*D>0:
  print(X-K*D)
else:
  if K%2==0:
    s=X-2*D*int(X/(2*D))
    t=-(s-2*D)
    print(min(abs(s),t))
    
  else:
    s=X-2*D*int((X-D)/(2*D))-D
    t=-(s-2*D)
    
    print(min(abs(s),t))
a=int(input())
b=int(input())
c=int(input())
x=int(input())/50
n=0
for i in range(x//10+1):
    n+=(x-10*i)//2+1

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
x=int(input())

l=[]
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            l.append(500*i+100*j+50*k)
n=0
for i in range(len(l)):
    if l[i]==x:
        n+=1
print(n)
a=input()
b=input()
c=input()
if a+b>c:
  print "yes"
else:
  print "no"

### FIXED CODE ###

a,b,c=map(int,raw_input().split())
if a+b>=c:
  print "Yes"
else:
  print "No"
n = int(input())
a_lst = list(map(int, input().split()))
index_lst = [0]*(a_max + 1)

for ai in a_lst:
    for multi in range(ai, a_max+1, ai):
        index_lst[multi] += 1

ans = 0
for ai in a_lst:
    if index_lst[ai] == 1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a_lst = list(map(int, input().split()))

a_max = max(a_lst)
index_lst = [0]*(a_max + 1)

for ai in a_lst:
    for multi in range(ai, a_max+1, ai):
        index_lst[multi] += 1

ans = 0
for ai in a_lst:
    if index_lst[ai] == 1:
        ans += 1
print(ans)
from collections import Counter

def check(A):
    N = len(A)
    even = Counter()
    odd = Counter()
    for i, a in enumerate(A):
        if i % 2 == 0:
            odd[a] += 1
        else:
            even[a] += 1
    
    even = even.most_common() + [(None, 0)]
    odd = odd.most_common() + [(None, 0)]
    
    if even[0][0] != odd[0][0]:
        return N - even[0][1] - odd[0][1]
    else:
        return min(N - even[0][1] - odd[1][1], N - odd[0][1] - even[1][1])
    
A = map(int, raw_input.split())
ans = check(A)
print A

### FIXED CODE ###

from collections import Counter


def check(A):
    N = len(A)
    even = Counter()
    odd = Counter()
    for i, a in enumerate(A):
        if i % 2 == 0:
            odd[a] += 1
        else:
            even[a] += 1
    
    even = even.most_common() + [(None, 0)]
    odd = odd.most_common() + [(None, 0)]
    
    if even[0][0] != odd[0][0]:
        return N - even[0][1] - odd[0][1]
    else:
        return min(N - even[0][1] - odd[1][1], N - odd[0][1] - even[1][1])

N = int(raw_input())
A = map(int, raw_input().split())

ans = check(A)
print ans
a,b,c = (str(x) for x in input().split())
if a == b == c
    print(No)
    else
        print(Yes)

### FIXED CODE ###

S = input()
if S[0] == S[1] == S[2]:
    print('No')
else:
    print('Yes')
n , k = map(int, input().split())

if n % k == 0:
    print("0"):
else:
    print("1")


### FIXED CODE ###

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

if n % k == 0:
    print("0")
else:
    print("1")
n = int(input())
x = [int(x)-i-1 for i, x in enumerate(input().split())]
x = sorted(zip(x, range(1, n+1)))

stack = []
for v, i in x[::-1]:
    for _ in range(i-1):
        stack.append(i)

cur = 0
ans = []
res = []
cnt = [0]*(n+1)
for i in range(n):
    for _ in range(x[i][0]-cur):
        if stack:
            nxt = stack.pop()
        elif res:
            nxt = res.pop()
        else:
            print('No')
            exit()
        ans.append(nxt)
        cnt[nxt] += 1
    if cnt[x[i][1]] < x[i][1]-1:
        print('No')
        exit()
    ans.append(x[i][1])
    for _ in range(n-x[i][1]):
        res.append(x[i][1])
    cur += x[i][0]

for v, i in x:
    if ans[v+i-1] != i:
        print('No')
        exit()

print('Yes')
print(*ans)


### FIXED CODE ###

n = int(input())
x = [int(x) for i, x in enumerate(input().split())]
x = sorted(zip(x, range(1, n+1)))

stack = []
for v, i in x[::-1]:
    for _ in range(i-1):
        stack.append(i)

cur = 1
ans = []
res = []
cnt = [0]*(n+1)
for i in range(n):
    for _ in range(x[i][0]-cur):
        if stack:
            nxt = stack.pop()
        elif res:
            nxt = res.pop()
        else:
            print('No')
            exit()
        ans.append(nxt)
        cnt[nxt] += 1
    if cnt[x[i][1]] != x[i][1]-1:
        print('No')
        exit()
    ans.append(x[i][1])
    for _ in range(n-x[i][1]):
        res.append(x[i][1])
    cur = x[i][0]+1

ans += res

print('Yes')
print(*ans)
# -*- coding: utf-8 -*-
from scratch import two_pointers
from operator import add, lt
from itertools import accumulate

n = int(input())
a = [int(_) for _ in input().split()]
cul_ary = [0] + list(accumulate(a, add))

l_split = 1
r_split = 3
griefs = []

for i in range(2, n - 1):
    l_split, l_diff, p, q = two_pointers(cul_ary,
                                         0,
                                         i,
                                         l_split,
                                         lambda ary, l, r: ary[r] - ary[l],
                                         lambda left, right: abs(left - right),
                                         lambda val1, val2: True if val1 > val2 else False)

    r_split, r_diff, r, s = two_pointers(cul_ary,
                                         i,
                                         n,
                                         r_split,
                                         lambda ary, l, r: ary[r] - ary[l],
                                         lambda left, right: abs(left - right),
                                         lambda val1, val2: True if val1 > val2 else False)

    griefs.append(max(p, q, r, s) - min(p, q, r, s))

print(min(griefs))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = [int(_) for _ in input().split()]

# my initial trial below ##############################
# from itertools import combinations
# combs = combinations(range(1, n), 3)
# grief = 10**10
# for comb in combs:
#     p = sum(a[:comb[0]])
#     q = sum(a[comb[0]:comb[1]])
#     r = sum(a[comb[1]:comb[2]])
#     s = sum(a[comb[2]:])

#     tmp = max(p, q, r, s) - min(p, q, r, s)
#     if tmp < grief:
#         grief = tmp

# print(grief)  # running time limit error

# solution below ######################################

cumul_sum = [0]
for i, ai in enumerate(a):
    cumul_sum.append(ai + cumul_sum[i])


def cal_sum(left, right):
    return cumul_sum[right] - cumul_sum[left]


def two_pointers(l, r, split, diff):
    for i in range(split, r):
        tmp_diff = abs(cal_sum(l, i) - cal_sum(i, r))
        if diff >= tmp_diff:
            diff = tmp_diff
        else:
            return i - 1, diff
    else:
        return r - 1, diff


l_split = 1
r_split = 3
griefs = []
for i in range(2, n - 1):
    # left
    l_split, l_diff = two_pointers(0, i, l_split, 10**12)
    # right
    r_split, r_diff = two_pointers(i, n, r_split, 10**12)

    p, q, r, s = cal_sum(0, l_split), cal_sum(l_split,
                                              i), cal_sum(i, r_split), cal_sum(
                                                  r_split, n)
    griefs.append(max(p, q, r, s) - min(p, q, r, s))


print(min(griefs))
a=list(map(int, input().split()))
l=[a[0]]
def d(a,b):
    if a==1 or b==1:
        return 0
    elif a<b:
        if min(l)!=b-a:
            l.append(b-a)
            d(b-a,a)
        else:
            return b-a
    elif b<a:
        if min(l)!=a-b:
            l.append(a-b)
            d(a-b,b)
        else:
            return a-b
print(d(a[0],a[1]))

### FIXED CODE ###

a=list(map(int, input().split()))
def d(a,b):
    _1=a%b
    _2=b-(a%b)
    if _1<_2:
        print(_1)
    else:
        print(_2)
d(a[0],a[1])
import sys
sys.setrecursionlimit(10**5)

N,Q=map(int,input().split())
tree=[[] for i in range(N)]

for i in range(N-1):
  a,b=map(int,input().split())
  if tree[a-1]==None:
    tree[a-1]=[b-1]
  else:
    tree[a-1].append(b-1)

point=[0]*N

beginpoint=[0]*N

def search(v,sum,parent):
  if v>=N:
    return
  else:
    herepoint=beginpoint[v]
    point[v]=sum+herepoint
    for j in range(len(tree[v])):
      if tree[v][j]==parent:
        return
      search(tree[v][j],point[v],v)

for i in range(Q):
  p,x=map(int,input().split())
  p=p-1
  beginpoint[p]=beginpoint[p]+x

search(0,0,-1)
  
print(*point)


### FIXED CODE ###

N,Q=map(int,input().split())
tree={}
for i in range(N-1):
  a,b=map(int,input().split())
  if (a-1) in tree:
    tree[a-1].append(b-1)
  else:
    tree[a-1]=[b-1]
  if (b-1) in tree:
    tree[b-1].append(a-1)
  else:
    tree[b-1]=[a-1]

point=[0]*N

for i in range(Q):
  p,x=map(int,input().split())
  point[p-1]+=x

ans=[0]*N
stack=[]
stack.append([0,0,-1])
while len(stack)>0:
  nodes=stack.pop()
  node=nodes[0]
  sump=nodes[1]
  parent=nodes[2]
  sump=sump+point[node]
  ans[node]=sump
  if node in tree:
      childs=tree[node]
      for child in childs:
        if child!=parent:
          stack.append([child,sump,node])

print(*ans)
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
else:
  s=X

for i in range (N):
  if X-i in L and X+i in L:
    pass
  elif X-i not in L:
    s=X-i
    break
  elif X-i in L and X+i not in L:
    s=X+i
    break
print(s)
  

### FIXED CODE ###

a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
  for i in range (N+1):
    if X-i in L and X+i in L:
      pass
    elif X-i not in L:
      s=X-i
      break
    elif X-i in L and X+i not in L:
      s=X+i
      break
else:
  s=X


print(s)
S=input()
T=input()
T.pop(len(str))
if(T==S):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S=input()
T=input()
if(T[:-1]==S):
  print("Yes")
else:
  print("No")
a, b = map(int, input().split())

if (a + b) % 2 === 0:
    print((a + b) // 2)
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

a, b = map(int, input().split())

if (a + b) % 2 == 0:
    print((a + b) // 2)
else:
    print("IMPOSSIBLE")
from scipy.misc import comb

N, M = map(int, input().split())

print(int(comb(N, 2) + comb(M, 2)))


### FIXED CODE ###

from math import factorial

N = int(input())
A = list(map(int, input().split()))

def comb(n, r):
    if n - r < 0:
        return 0
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))

nums = [0] * (N + 1)
for i, v in enumerate(A):
    nums[v] += 1
combs = list(map(lambda n: comb(n, 2), nums))
total = sum(combs)

for k, val in enumerate(A):
    print(total - (nums[val] - 1))
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def resolve():
    n, m = map(int, input().split())

    if n == m:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def resolve():
    c = input()

    print(chr(ord(c)+1))


if __name__ == "__main__":
    resolve()
W, H, x, y, r = map(int, raw_input().split))
 
if 0 <= (x-r) and (x+r) <= W and 0 <= (y-r) and (y+r) <= H:
 print 'Yes'
else:
 print 'No'

### FIXED CODE ###

W, H, x, y, r = map(int, raw_input().split())
 
if r <= x and x + r <= W and r <= y and y + r <= H:
 print 'Yes'
else:
 print 'No'
n=input()
for i in range(3):
  if n[i]=="1":
    n[i]=9
  else:
    n[i]=1
print(n)

### FIXED CODE ###

n=input()
ans=""
for i in range(3):
  if n[i]=="1":
    ans+="9"
  else:
    ans+="1"
print(ans)
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]

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

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    l[a].append(b)
    l[b].append(a)

p = [-1] * (N + 1)
c = [-1] * (N + 1)
c[1] = 0


def dfs(i):
    if len(l[i]) == 0:
        return
    for j in range(len(l[i])):
        point = l[i][j]
        if c[point] == -1 or c[point] > c[i] + 1:
            p[point] = i
            c[point] = c[i] + 1
            dfs(point)
        else:
            continue


dfs(1)
flag = 1

for i in range(2, N + 1):
    if c[i] == -1:
        flag = 0
if flag == 0:
    print('No')
else:
    print('Yes')
    for i in range(2, N + 1):
        print(p[i])

### FIXED CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]
 
l = [[] for i in range(N + 1)]
 
for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    l[a].append(b)
    l[b].append(a)
 
point = [0] * (N + 1)
search = [0] * (N + 1)
search[1] = 1

que = []
que.append(1)
p = 0

while len(que) != N:
    now = que[p]
    for i in range(len(l[now])):
        n = l[now][i]
        if search[n] == 0:
            search[n] = 1
            que.append(n)
            point[n] = now
    p += 1
    
print('Yes')
for i in range(2,N+1):
    print(point[i])
import sys

A,B,K = map(int, input().split())
for i in range(A,B+1):
  if i <= A + K-1 or i>= B-K+1:
    print(i)

### FIXED CODE ###

import sys

S = input()
T = "abc"
if len(S) > 3:
  print("No")
else:
  for i in S:
    if i in T:
      T = T.replace(i,'')
    else:
      print("No")
      sys.exit()
  print("Yes")
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()
A = [list(input()) for i in range(h)]

def bfs():
    que = deque([])
    
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    d = [[INF] * w for i in range(h)]
     
    for i in range(h):
        for j in range(w):
            if A[i][j] == "#":
                sy, sx = j, i
                d[sy][sx] = 0
                que.append((sy, sx))
    while que:
        p = que.popleft()
        for i in range(4):
            ny, nx = p[0] + dy[i], p[1] + dx[i]
            
            if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == INF:
                d[ny][nx] = d[p[0]][p[1]] + 1
                A[ny][nx] = "#"
                que.append((ny, nx))
                 
    return d

ans = 0
for l in bfs():
    ans = max(ans, max(l))
print(ans)




### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()
A = [list(input()) for i in range(h)]


def bfs():
    que = deque([])
    
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    d = [[INF] * w for i in range(h)]
    
    for i in range(h):
        for j in range(w):
            if A[i][j] == "#":
                sy, sx = i, j
                d[sy][sx] = 0
                que.append((sy, sx))
    ans = 0
    while que:
        p = que.popleft()
        for i in range(4):
            ny, nx = p[0] + dy[i], p[1] + dx[i]
            
            if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == INF and A[ny][nx] == ".":
                d[ny][nx] = d[p[0]][p[1]] + 1
                # A[ny][nx] = "#"
                que.append((ny, nx))
 
                ans = max(ans, d[ny][nx])     
#    print(*d, sep="\n")
    return ans


if __name__ == "__main__":
    print(bfs())
a,b = int(input().split())
S = a*b
C = 2 * (a+b)

print(S + " " + C)


### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)
S = a*b
C = 2 * (a+b)

print(str(S) + " " + str(C))
int x = int(input())
if x >= 30:
  print("yes")
else:
  print("no")

### FIXED CODE ###

x = int(input())
if x >= 30:
  print("Yes")
else:
  print("No")
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(-100,1000)
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(ans)
  else:
    for j in range(1000):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
  print(ans)

### FIXED CODE ###

X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(102))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(X)
  else:
    for j in range(100):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
    print(ans)
from collections import deque

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]

def bfs(grid, start):
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0#start地点を0に
    
    while queue:#queueにたまっている間は処理を続ける
        x, y = queue.popleft()#今いる地点をpop
        
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):#左右上下に進むパターンをそれぞれ考える
            next_x, next_y = x+i, y+j#次に行く地点
            
            if 0 <= next_x < W and 0 <= next_y < H:#次の地点が範囲内にある場合
                if grid[next_y][next_x] == '.' and distance[next_y][next_x] == -1:#次の地点が壁ではなくかつ訪れたことがない場合
                    distance[next_y][next_x] = distance[y][x] + 1#訪れた印として現在までの距離に1を足す
                    queue.append((next_x, next_y))#訪れる先をqueueに詰めとく
        
        if not queue:#最後にqueueをpopし終えてなくなったら最後に出力
            return distance[y][x]
        
answer = 0
for i in range(H):
    for j in range(W):
        #スタート地点を決める
        
        if S[i][j] == '#':#スタート地点が壁
            continue

        tmp = bfs(S, (i, j))#このスタート地点での一番遠い距離
        
        if tmp > answer:#最大の距離
            answer = tmp

print(answer)   

### FIXED CODE ###

from collections import deque

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]

def bfs(grid, start):
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[1]][start[0]] = 0#start地点を0に
    
    while queue:#queueにたまっている間は処理を続ける
        x, y = queue.popleft()#今いる地点をpop
        
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):#左右上下に進むパターンをそれぞれ考える
            next_x, next_y = x+i, y+j#次に行く地点
            
            if 0 <= next_x < W and 0 <= next_y < H:#次の地点が範囲内にある場合
                if grid[next_y][next_x] == '.' and distance[next_y][next_x] == -1:#次の地点が壁ではなくかつ訪れたことがない場合
                    distance[next_y][next_x] = distance[y][x] + 1#訪れた印として現在までの距離に1を足す
                    queue.append((next_x, next_y))#訪れる先をqueueに詰めとく
        
        if not queue:#最後にqueueをpopし終えてなくなったら最後に出力
            return distance[y][x]
        
answer = 0
for i in range(H):#y
    for j in range(W):#x
        #スタート地点を決める
        
        if S[i][j] == '#':#スタート地点が壁
            continue

        tmp = bfs(S, (j, i))#このスタート地点での一番遠い距離
        
        if tmp > answer:#最大の距離
            answer = tmp

print(answer)