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

n = input()
lis = []
for i in xrange(n):
    com = raw_input()
    try:
        com, x = com.split()
        if   com == 'insert':
            lis.append(x)
        elif com == 'delete':
            l = len(lis) - 1
            while (lis[l] != x) and l >= 0:
                l -= 1
            if lis[l] == x:
                lis.pop(l)
    except:
        if com == 'deleteFirst':
            lis.pop()
        if com == 'deleteLast':
            lis.pop(0)

print " ".join( map(str, reversed(lis)) )

### FIXED CODE ###

n = input()
lis = []
bot = 0
for i in xrange(n):
    com = raw_input()
    if   com[0] == 'i':
        lis.append(com[7:])
    elif com[6] == ' ':
        try:
            lis.pop(~lis[::-1].index(com[7:]))
        except:
            pass
    elif com[6] == 'F':
        lis.pop()
    else:
        bot += 1

print ' '.join( map(str, reversed(lis[bot:])) )
### BUGGY CODE ###

import numpy as np
N, K = map(int, input().split())
H = list(int(x) for x in input().split())

dp = np.full(N, np.inf)
dp[0] = 0
H = np.array(H)

for i in range(1, N):
    dp[i] = min(dp[max(0,i-K):i] + abs(H[i] - H[max(0,i-K):i]))

print(int(dp[N-1]))

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
H = list(int(x) for x in input().split())

dp = np.full(N, np.inf)
dp[0] = 0
H = np.array(H)

for i in range(1, N):
    j = max(0,i-K)
    dp[i] = min(dp[j:i] + np.abs(H[i] - H[j:i]))

print(int(dp[N-1]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(400000000)
n,k=map(int,input().split())
h=list(map(int,input().split()))
flog=[-1]*n
#初期値は0
def Num(dest):
    if flog[dest-1]>0:
        return flog[dest-1]
    if dest<k+2:
        res=abs(h[dest-1]-h[0])
        flog[dest-1]=res
        return res
    else:
        min=Num(dest-1)+abs(h[dest-1]-h[dest-1-1])
        for i in range(2,k+1):
            tmp=Num(dest-i)+abs(h[dest-1]-h[dest-i-1])
            if min>tmp:
                min=tmp
        flog[dest-1]=min
        return min   
print(Num(n))

### FIXED CODE ###

import sys
sys.setrecursionlimit(400000000)
def main():
    n,k=map(int,input().split())
    h=tuple(map(int,input().split()))
    flog=[-1]*n
    for i in range(n):#dest=i 0が１
        if i<k+1:#0~k
            flog[i]=abs(h[i]-h[0])
        else:
            min=10**9
            for j in range(1,k+1):#1~k
                tmp=flog[i-j]+abs(h[i]-h[i-j])
                if tmp<min:
                    min=tmp
            flog[i]=min
    print(flog[n-1])
   # print(flog)
if __name__=="__main__":
    main()
### BUGGY CODE ###

N = int(input())
s = []
for _ in range(N):
	s.append(sorted([a for a in input()]))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

### FIXED CODE ###

def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()
### BUGGY CODE ###

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

ans = []
for i in range(N):
    a, b = map(int, input().split())
    for _ in range(b):
        ans.append(a)

print(sorted(ans)[K-1])

### FIXED CODE ###

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

A = [0] * 10**5

for i in range(N):
    a, b = map(int, input().split())
    A[a-1] += b

c = 0

for i in range(10**5):
    c += A[i]
    if c >= K:
        break

print(i+1)
### BUGGY CODE ###

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
ary = []
for i in range(1,N+1):
    ary.append(i)

cumsum = list(itertools.accumulate(ary))

for i in range(len(cumsum)):
    if cumsum[i] >= N:
        ans = i
        break
print(ans+1)


### FIXED CODE ###

x = int(input())

for i in range(10**5):
    if 2*x <= (i+1)*i:
        print(i)
        break
### BUGGY CODE ###

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

def calc(a):
    for t in range(k):
        b = [0] * n
        for i in range(n):
            for j in range(n):
                if a[j] >=  abs(j - i):
                    b[i] += 1

        for i in range(n):
            if(max(n-i,i) > b[i]):
                break
            for j in range(n):
                a[j] += n *(k-t)
            return a
        a = b
    return a

a = calc(a)
for i in a:
    print(i,end=" ")
        

### FIXED CODE ###

from math import log2
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n

if(k > 10*log2(n) + 1):
    for i in range(n):
        print(n,end=" ")

else:
    for j in range(k):
        b = [0]*n
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n-1,a[i]+i)
            b[l] += 1
            if(r+1<n):
                b[r+1] -= 1
        for i in range(1,n):
            b[i] += b[i-1]
        a = b


    for i in a:
        print(i,end=" ")
### BUGGY CODE ###

# C - Good Sequence
N = int(input())
a = list(map(int, input().split()))
count = 0

a.sort(reverse=True)
a_1 = list(set(a))
for i in range(len(a_1)):
    if a_1[i] == a.count(a_1[i]):
        pass
    elif a_1[i] < a.count(a_1[i]):
        count += a.count(a_1[i])-a_1[i]
    else:
        count += a.count(a_1[i])

print(count)

### FIXED CODE ###

# C - Good Sequence
import collections
N = int(input())
a = list(map(int, input().split()))
count = 0

a_1 = collections.Counter(a)

for k,v in a_1.items():
    if k <= v:
        count += v-k
    else:
        count += v

print(count)
### BUGGY CODE ###

N = int(input())
array = list(map(int,input().split()))
ans = []
for i in range(N-1):
  product = []
  for j in range(1,N-i):
    product.append(array[i]*array[i+j])
  ans.append(sum(product))
print( sum(ans)%(10**9+7) )

### FIXED CODE ###

N = int(input())
array = list(map(int,input().split()))
ans = 0
kuso = sum(array)
for i in range(N-1):
  kuso -= array[i]
  ans += array[i]*kuso  
print( ans%(10**9+7) )
### BUGGY CODE ###

N,M = map(int, input().split())
# 市 i は　県 n (N)で x 番目に誕生した
li = []
pre = [[] for i in range(N)]
for i in range(M):
    p,y = map(int, input().split())
    pre[p-1].append(y)
    li.append([p,y])
pre = list(map(sorted,pre))
for p,y in li:
    print("{:0=6}".format(p) + "{:0=6}".format(pre[p-1].index(y)+1))

### FIXED CODE ###

import bisect
N,M = map(int, input().split())
q = [[int(j) for j in input().split()] for i in range(M)]
li = [[] for k in range(N+1)]

for i,j in sorted(q):
    li[i].append(j)

for p,y in q:
    z = bisect.bisect(li[p],y)
    print("{:0=6}".format(p) + "{:0=6}".format(z))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 21:21:19 2019

@author: Yamazaki Kenichi
"""

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

def a(b,i):
    if i == -1 or i == N:
        return i        
    if b[0] == s[i]:
        return i - 1 if b[1] == 'L' else i + 1
    else:
        return i
def ar(i):
    for j in range(Q):
        if i == N:
            return False
        i = a(A[j],i)
    return False if i == N else True
def al(i):
    for j in range(Q):
        if i == -1:
            return False
        i = a(A[j],i)
    return False if i == -1 else True
def bir(i,j):
    if i + 1 == j:
        return i
    if ar((i+j)//2):
        return bir((i+j)//2,j)
    else:
        return bir(i,(i+j)//2)
def bil(i,j):
    if i + 1 == j:
        return i
    if al((i+j)//2):
        return bil(i,(i+j)//2)
    else:
        return bil((i+j)//2,j)
ans = bir(0,N) - bil(0,N)
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 21:21:19 2019

@author: Yamazaki Kenichi
"""

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

def a(b,i):
    if i == -1 or i == N:
        return i        
    if b[0] == s[i]:
        return i - 1 if b[1] == 'L' else i + 1
    else:
        return i
def ar(i):
    for j in range(Q):
        if i == N:
            return False
        i = a(A[j],i)
    return False if i == N else True
def al(i):
    for j in range(Q):
        if i == -1:
            return False
        i = a(A[j],i)
    return False if i == -1 else True
def bir(i,j):
    if i + 1 == j:
        return i
    if ar((i+j)//2):
        return bir((i+j)//2,j)
    else:
        return bir(i,(i+j)//2)
def bil(i,j):
    if i + 1 == j:
        return i
    if al((i+j)//2):
        return bil(i,(i+j)//2)
    else:
        return bil((i+j)//2,j)
ans = bir(0,N) - bil(0,N)
print(ans)
### BUGGY CODE ###

from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=10**19
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  que=[]
  d=[INF]*n
  d[s]=0
  visited={s}
  heappush(que,[0,s])
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,[d[node],node])
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
l=[INF]
for i in range(n-1,-1,-1) :
  l.append(min(l[-1],yen[i]+snu[i]))
for i in l[n:0:-1]:
  print(10**15-i)


### FIXED CODE ###

from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=10**19
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  que=[]
  d=[INF]*n
  d[s]=0
  visited={s}
  heappush(que,[0,s])
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,[d[node],node])
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
ans=10**15
ans_list=[]
for i in reversed(range(n)):
  ans=min(ans,yen[i]+snu[i])
  ans_list.append(10**15-ans)
print(*ans_list[::-1], sep='\n')
### BUGGY CODE ###

from collections import defaultdict

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

MOD = 10 ** 9 + 7

# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

counter = defaultdict(int)
p_list = []
for a in A:
  for p, r in factorization(a):
    if counter[p] == 0:
      p_list.append(p)
    counter[p] = max(counter[p], r)
lcm = 1
for p in p_list:
  lcm *= pow(p, counter[p])
  
answer = 0
for a in A:
  answer = (answer + lcm // a) % MOD

print(answer)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

N, K = map(int, input().split())
# A = sorted(list(map(int, input().split())),reverse=True)
A = list(map(int, input().split()))

uniq_items = []
for i in set(A):
    uniq_items.append(A.count(i))
    uniq_items = sorted(uniq_items,reverse=True)

if len(uniq_items) <= K:
    print(0)
else:
    print(sum(uniq_items[K:]))

### FIXED CODE ###

from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))

print(sum(sorted(Counter(A).values(),reverse=True)[K:]))
### BUGGY CODE ###

N,W = map(int, input().split())
V = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(W+1):
    for j in range(N):
        w = V[j][0]
        v = V[j][1]
        if w <= i:    
            dp[j+1][i] = max(dp[j][i-w]+v,dp[j][i])
        else:
            dp[j+1][i] = dp[j][i]

print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
 
import numpy as np
dp = np.zeros(W + 1, dtype='int64')
 
for i in range(1, N + 1):
    w, v = map(int, input().split())
    dp[w:W+1] = np.maximum(dp[w:W+1], dp[:W-w+1] + v)
 
print(dp[-1])
### BUGGY CODE ###

import math

route_list = [[0, 50, 80, 0, 0], [0, 0, 20, 15, 0 ], [0, 0, 0, 10, 15], [0, 0, 0, 0, 30], [0, 0, 0, 0, 0]] # 初期のノード間の距離のリスト

node_num = int(input())
nodes=input().split()

route_list=[]

for _ in range(node_num):
    route_list.append([ -1 for _ in range(node_num)])

for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i]))
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i]))
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i]))

#print(route_list)


unsearched_nodes = list(range(node_num)) # 未探索ノード
distance = [100000000] * node_num # ノードごとの距離のリスト
previous_nodes = [-1] * node_num # 最短経路でそのノードのひとつ前に到達するノードのリスト
distance[0] = 0 # 初期のノードの距離は0とする

# @GDaigo さんのコメントより関数の追加 2017/03/18
def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0): #未探索ノードがなくなるまで繰り返す
    # まず未探索ノードのうちdistanceが最小のものを選択する
    posible_min_distance = 100000000# 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
    for node_index in unsearched_nodes: # 未探索のノードのループ
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes) # 未探索ノードのうちで最小のindex番号を取得
    unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去

    target_edge = route_list[target_min_index] # ターゲットになるノードからのびるエッジのリスト
    for index, route_dis in enumerate(target_edge):
        if route_dis != -1:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
                previous_nodes[index] =  target_min_index #　ひとつ前に到達するノードのリストも更新

# 以下で結果の表示
"""
print("-----経路-----")
previous_node = node_num - 1
while previous_node != -1:
    if previous_node !=0:
        print(str(previous_node + 1) + " <- ", end='')
    else:
        print(str(previous_node + 1))
    previous_node = previous_nodes[previous_node]

print("-----距離-----")
"""
print(distance[node_num - 1])

### FIXED CODE ###

N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])
### BUGGY CODE ###


def main():
    n = int(input())
    *A, = map(int, input().split())
    a = 1
    for i in A:
        a*=i
    if a > 10**18:
        print(-1)
    else :
        print(a)

if __name__ == "__main__":
    main()

### FIXED CODE ###


def main():
    n = int(input())
    *A, = map(int, input().split())
    a = 1
    if 0 in A:
        print(0)
    else :
        for i in A:
            a*=i
            if a > 10**18:
                print(-1)
                break
        else :
            print(a)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a = list(map(int, input().split()))
    b = [0]*n
    for _ in range(n):
        b[a[_]-1] = _
    r = (b[0]+1) * (n-b[0])
    c = [b[0]]
    m = 2
    for i in b[1:]:
        ri = bisect.bisect(c, i)
        if ri == 0:
            r += (i+1) * (c[ri]-i) * m
        elif ri == m-1:
            r += (i-c[ri-1]) * (n-i) * m
        else:
            r += (i-c[ri-1]) * (c[ri]-i) * m
        m += 1
        c = c[:ri] + [i] + c[ri:]

    return r

print(f())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a = list(map(int, input().split()))
    l = list(range(n+2))
    r = list(range(n+2))
    b = [0]*(n+2)
    for i, x in enumerate(a, 1):
        b[x] = i
    c = 0
    for i in range(n,0,-1):
        bi = b[i]
        c += i * (r[bi] - bi + 1) * (bi - l[bi] + 1)
        r[l[bi]-1] = r[bi]
        l[r[bi]+1] = l[bi]
    return c

print(f())
### BUGGY CODE ###

S=input()
T=input()
lS=len(S)
lT=len(T)
ans=[[""]*lS for _ in range(lT)]
for iT in range(lT):
  for iS in range(lS):
    if S[iS]==T[iT]:
      if iS-1>=0 and iT-1>=0:
        ans[iT][iS]=ans[iT-1][iS-1]+S[iS]
      else:
        ans[iT][iS]=S[iS]
    else:
      if iS-1>=0 and (iT-1<0 or len(ans[iT][iS-1])>=len(ans[iT-1][iS])):
        ans[iT][iS]=ans[iT][iS-1]
      elif iT-1>=0 and (iS-1<0 or len(ans[iT-1][iS])>=len(ans[iT][iS-1])):
        ans[iT][iS]=ans[iT-1][iS]
print(ans[lT-1][lS-1])

### FIXED CODE ###

import sys
def main():
  S=list(sys.stdin.readline())[:-1]
  T=list(sys.stdin.readline())[:-1]
  lS=len(S)
  lT=len(T)
  dp=[[0]*(lS+1) for _ in range(lT+1)]
  for iT in range(lT):
    for iS in range(lS):
      if S[iS]==T[iT]:
        dp[iT+1][iS+1] = max(dp[iT+1][iS],dp[iT][iS+1],dp[iT][iS]+1)
      else:
        dp[iT+1][iS+1] = max(dp[iT+1][iS],dp[iT][iS+1])

  iS = lS
  iT = lT
  ans = ""
  while(iS>0 and iT>0):
    if dp[iT][iS]==dp[iT-1][iS-1]:
      iS -= 1
      iT -= 1
    elif dp[iT][iS]==dp[iT][iS-1]:
      iS -= 1
    elif dp[iT][iS]==dp[iT-1][iS]:
      iT -= 1
    else:
      ans = S[iS-1]+ans
      iS -= 1
      iT -= 1
  print(ans)

if __name__ == '__main__':
  main()
### BUGGY CODE ###

n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[i])
print(0)

### FIXED CODE ###

n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[i])
print(0)
### BUGGY CODE ###

import re

N, Q = [int(item) for item in re.split(r"\s", input())]
s = input()
TD = [input().split() for i in range(Q)]


def check(i):
    """どっちに落ちるかを返す
    -1,0,1

    Args:
        i ([type]): [description]
    """

    if i == -1:
        return -1
    if i == N:
        return 1

    for q in range(Q):
        t, d = TD[q]
        if t == s[i]:
            if d == "L":
                i -= 1
            if d == "R":
                i += 1

            if i == -1:
                return -1
            if i == N:
                return 1
    return 0


s_index = -1  # include
e_index = N  # include
while s_index+1 < e_index:
    c_index = (s_index+e_index)//2
    if check(c_index) == -1:
        s_index = c_index
    else:
        e_index = c_index
left = s_index

s_index = -1  # include
e_index = N  # include
while s_index+1 < e_index:
    c_index = (s_index+e_index)//2
    if check(c_index) == 1:
        e_index = c_index
    else:
        s_index = c_index
right = e_index


print(right-left-1)


### FIXED CODE ###

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


def simulate(n):
    if n == -1:
        return -1
    if n == N:
        return 1
    for t, d in TD:
        if t == s[n]:
            if d == "L":
                n -= 1
            else:
                n += 1
        if n == -1:
            return -1
        elif n == N:
            return 1
    return 0


l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == -1:
        l = n
    else:
        r = n
L = l

l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == 1:
        r = n
    else:
        l = n
R = r
print(R-L-1)
### BUGGY CODE ###

import copy
from collections import deque

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

# フィールドを作る
for h in range(H + 2):
    field_s.append(["#"] * (W + 2))
    if 1 <= h <= (H):
        field_s[h][1:-1] = list(map(str, input().rstrip()))

#　動き方のセットを準備
moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

# スタートとゴールの座標の組み合わせを作成
sg = []
for y in range(H + 2):
    for x in range(W + 2):
        if field_s[y][x] == ".":
            sg.append([y, x])

# 答え
ans = 0

# スタートとゴールの座標を組み合わせてぐるぐる
for s in sg:
    for g in sg:

        # startとgoalの座標が同じならスキップ
        if s == g:
            continue

        # fieldの初期化
        field = copy.deepcopy(field_s)

        # startをキューに追加
        que = deque([s])

        # startの距離は0に
        field[s[0]][s[1]] = 0

        # キューに何かがある限り探索を続ける
        while que:
            c = que.popleft()

            # 今の距離
            dist = field[c[0]][c[1]]

            # 動いた先が「.」なら、距離を記録してキューに追加
            for m in moves:
                my = c[0] + m[0]
                mx = c[1] + m[1]

                if field[my][mx] == ".":
                    field[my][mx] = dist + 1
                    que.append([my, mx])
                else:
                    continue

                # もしゴールに到達していたらansを差し替えてbreak
                if [my, mx] == g:
                    ans = max(ans, field[my][mx])
                    break

print(ans)

### FIXED CODE ###

import copy
from collections import deque

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

# フィールドを作る
for h in range(H + 2):
    field_s.append(["#"] * (W + 2))
    if 1 <= h <= (H):
        field_s[h][1:-1] = list(map(str, input().rstrip()))

#　動き方のセットを準備
moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

# スタート座標を取得
start = []
for y in range(1, H + 1):
    for x in range(1, W + 1):
        if field_s[y][x] == ".":
            start.append([y, x])

# 答え
ans = 0

for s in start:

    # fieldの初期化
    field = copy.deepcopy(field_s)

    # startをキューに追加
    que = deque([s])

    # startの距離は0に
    field[s[0]][s[1]] = 0

    # キューに何かがある限り探索を続ける
    while que:
        c = que.popleft()

        # 今の距離
        dist = field[c[0]][c[1]]

        # 動いた先が「.」なら、距離を記録してキューに追加
        for m in moves:
            my = c[0] + m[0]
            mx = c[1] + m[1]

            if field[my][mx] == ".":
                field[my][mx] = dist + 1
                que.append([my, mx])
            else:
                continue
    
    # キューを消化したら最大値を取り出す
    field = sum(field, [])
    ans = max(ans, max([x for x in field if type(x)==int]))

print(ans)