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

from scipy.sparse import*
from itertools import permutations as pm

n,m,h = map(int,input().split())
r = [int(i) for i in input().split()]

A = lil_matrix((n+1,n+1))
for i in range(m):
  u,v,l = map(int,input().split())
  A[u,v] = l

A=csgraph.dijkstra(A.tocsr(),0)

s=min(sum(A[i][j] for i,j in zip(a[:-1],a[1:])) for a in pm(r))
print(int(s))

### FIXED CODE ###

from scipy.sparse import*
from itertools import permutations as pm

n,m,h = map(int,input().split())
r = [int(i) for i in input().split()]

u,v,l = zip(*[map(int,input().split()) for i in range(m)])

A=csgraph.dijkstra(csr_matrix((l,(u,v)),(n+1,n+1)),0)

s=min(sum(A[i][j] for i,j in zip(a[:-1],a[1:])) for a in pm(r))
print(int(s))
### BUGGY CODE ###

k = int(input())
s = input()
mod = 10**9+7
n = len(s)
fact =[1]*(k+n)
factinv = [1]*(k+n)
inv = [0,1]
 
 
for i in range(2,k+n):
    fact[i] = (fact[i-1] * i) % mod
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv[i] = (factinv[i-1] * inv[i]) % mod

def nCr(n,r):
  r = min(r,n-r)
  return (fact[n] * factinv[r] * factinv[n-r])%mod
ans = 0
for i in range(k+1):
  a = pow(25, i, mod)
  a *= nCr(i+n-1, n-1)
  a *= pow(26,k-i, mod)
  ans += a
  ans %= mod
print (ans)

### FIXED CODE ###

k = int(input())
s = input()
mod = 10**9+7
n = len(s)
fact =[1]*(k+n)
factinv = [1]*(k+n)
inv = [0,1]
 
 
for i in range(2,k+n):
    fact[i] = (fact[i-1] * i) % mod
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv[i] = (factinv[i-1] * inv[i]) % mod

def nCr(n,r):
  r = min(r,n-r)
  return (fact[n] * factinv[r] * factinv[n-r])%mod
ans = 0
for i in range(k+1):
  a = pow(25, i, mod)
  a *= nCr(i+n-1, n-1)
  a *= pow(26,k-i, mod)
  ans += a
  ans %= mod
print (ans)
### BUGGY CODE ###

def resolve():
    n = int(input())
    am = []

    from collections import deque

    for i in range(n):
        am.append(deque(list(map(lambda x: int(x) - 1, input().split()))))

    cnt = n * (n - 1) // 2

    day = 0
    while cnt > 0:
        day += 1
        match = 0
        done = {}
        for i in range(n):
            if i in done:
                continue
            if len(am[i]) == 0:
                continue
            j = am[i][0]
            if j not in done and am[j][0] == i:
                am[i].popleft()
                am[j].popleft()
                done[i] = 1
                done[j] = 1
                match += 1

        if match == 0:
            print(-1)
            return
        else:
            cnt -= match

    print(day)
    
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = []

    for i in range(n):
        row = list(map(lambda x: int(x) - 1, input().split()))
        row.reverse()
        a.append(row)

    q = set()

    def check(i):
        if len(a[i]) == 0:
            return
        j = a[i][-1]
        if i == a[j][-1]:
            p = (i, j) if i < j else (j, i)
            q.add(p)

    for i in range(n):
        check(i)

    day = 0
    while len(q) > 0:
        day += 1
        prev_q, q = q, set()

        for p in prev_q:
            (i, j) = p
            a[i].pop()
            a[j].pop()

        for p in prev_q:
            (i, j) = p
            check(i)
            check(j)

    for i in range(n):
        if len(a[i]) != 0:
            print(-1)
            return
    print(day)
    
resolve()
### BUGGY CODE ###

import numpy as np
import math

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

for i in range(m):
    idx = np.argmax(a)
    if a[idx] != 0:
        a[idx] /= 2

for i in range(n):
    a[i] = math.floor(a[i])

print(int(sum(a)))

### FIXED CODE ###

# ABC141 D - Powerful Discount Tickets
from heapq import heappop,heappush,heapify

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

a_minus = [-x for x in a]

heapify(a_minus)

for _ in range(m):
    heappush(a_minus,-((-heappop(a_minus))//2))
ans = -sum(a_minus)
print(int(ans))
### BUGGY CODE ###


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

data = {}
ps = []
ACs = []
for i in range(M):
    p, S = input().split()
    p = int(p)

    if not (p in ps):
        ps.append(p)
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] ==0:
        ACs.append(p)
        data[p]['AC'] += 1

    if S == 'WA' and data[p]['AC']==0:
        data[p][S] += 1

ans = 0
for p in ACs:
    ans += data[p]['WA']

print(len(ACs), ans)



### FIXED CODE ###


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

data = {}
ps = [0] * N
ACs = []

num_ac = 0
num_wa = 0


for i in range(M):
    p, S = input().split()
    p = int(p) - 1

    if ps[p] == 0:
        ps[p] = 1
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] == 0:
        ACs.append(p)
        data[p]['AC'] += 1
        num_ac += 1
        num_wa += data[p]['WA']

    if S == 'WA' and data[p]['AC'] == 0:
        data[p][S] += 1

print(num_ac, num_wa)
### BUGGY CODE ###

n= int(input())
li=list(map(int,input().split()))
for i in range(1,n+1):
  print(li.count(i))

### FIXED CODE ###

import collections

n= int(input())
li=list(map(int,input().split()))
c=collections.Counter(li)

for i in range(1,n+1):
  print(c[i])
### BUGGY CODE ###

x = int(input())

a = 1
b = 0

while a ** 5 <= x:
    a += 1
if x >= a ** 5 - (a - 1) ** 5:
    is_pos = True
else:
    is_pos = False
    a -= 1

tmp = 1 if is_pos else -1

while a ** 5 - b ** 5 != x:
    b += tmp


print(a, b)


### FIXED CODE ###

x = int(input())
LIMIT = 10 ** 9
lmt = 0

while lmt ** 5 - (lmt - 1) ** 5 <= LIMIT:
    lmt += 1


for a in range(-lmt, lmt + 1):
    for b in range(-lmt, a + 1):
        # print(a, b)
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()
### BUGGY CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
for i in range(q):
    t = s[l[i][0]-1:l[i][1]]
    c = 0
    for j in range(len(t)-1):
        if t[j] == "A":
            if t[j+1] == "C":
                c += 1
        else:
            continue
    print(c)

### FIXED CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
c = [0 for i in range(n)]
cc = 0
f = False
for i in range(n):
    if f:
        f = False
        if s[i] == "C":
            cc += 1
    if s[i] == "A":
        f = True
    c[i] = cc
for i in range(q):
    print(c[l[i][1]-1]-c[l[i][0]-1])
### BUGGY CODE ###

N, Y = map(int, input().split())
nn = Y // 10000 if (Y // 10000) < N else N
mm = Y // 5000  if (Y // 5000)  < N else N
ll = Y // 1000  if (Y // 1000)  < N else N

#print(nn, mm, ll)
ans = "-1 -1 -1"
for i in range(nn+1):
  for j in range(mm+1):
    if i + j > N:
      break
    for k in range(ll+1):
      if i + j + k > N:
        break
      if i + j + k != N:
        next
      else:
        #print(i, j, k)
        if (i * 10000 + j * 5000 + k * 1000) == Y:
          ans = str(i)+" "+str(j)+" "+str(k)
          break
print(ans)
  

### FIXED CODE ###

N, Y = map(int, input().split())
nn = Y // 10000 if (Y // 10000) < N else N
mm = Y // 5000  if (Y // 5000)  < N else N
ll = Y // 1000  if (Y // 1000)  < N else N

#print(nn, mm, ll)
ans = "-1 -1 -1"
for i in range(nn+1):
  for j in range(mm+1):
    if i + j > N:
      break
    if (i * 10000 + j * 5000 + (N-i-j) * 1000) == Y:
          ans = str(i)+" "+str(j)+" "+str(N-i-j)
          break
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    alis = list(map(int, input().split()))
    adic = {}
    for num in alis:
        if num in adic:
            adic[num] += 1
        else:
            adic[num] = 1
    
    anslis = []

    q = int(input())
    bclis = []
    for i in range(q):
        b, c = map(int,input().split())
        if b in adic:
            kazu = adic[b]
            adic[b] = 0
            if c in adic:
                adic[c] += kazu
            else:
                adic[c] = kazu
        ans = 0
        for key in adic:
            ans += adic[key] * key
        print(ans)
    
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    alis = sorted(map(int, input().split()))
    total = sum(alis)
    adic = {}
    for num in alis:
        if num in adic:
            adic[num] += 1
        else:
            adic[num] = 1
    
    anslis = []

    q = int(input())
    bclis = []
    for i in range(q):
        b, c = map(int,input().split())
        if b in adic:
            kazu = adic[b]
            adic[b] = 0
            total -= b * kazu
            if c in adic:
                adic[c] += kazu
            else:
                adic[c] = kazu
            total += c * kazu
        print(total)
    
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



def main_sum():
    N,M,K=map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1

    ans = 0
    for i in reversed(range(maxA)):
        for j in range(maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j

    print(ans)




main_sum()


### FIXED CODE ###

import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



def main_sum():
    N,M,K=map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = len(A) + 1
    maxB = len(B) + 1

    add = 0
    for i in range(1,A_len+1):
        Asum[i] = A[i-1] + Asum[i-1]

    add = 0
    for i in range(1,B_len+1):
        Bsum[i] = B[i-1] + Bsum[i-1]

    ans = 0
    prev = 0
    for i in reversed(range(maxA)):
        for j in range(prev,maxB):
            if Asum[i] + Bsum[j] <= K:
                prev = j
                if ans < i + j:
                    ans = i + j
                if j == (maxB - 1):
                    print(ans)
                    exit()
            else:
                break

    print(ans)




main_sum()
### BUGGY CODE ###

N = int(input())
S = list(str(input()) for _ in range(N))
S2 = sorted(S)
cnt1 = [0,]
cnt2 = [0,]*N
word = [0,]
for i in range(N-1):
    if S2[i] != S2[i+1]:
        cnt1.append(i+1)
        word.append(S2[i])
cnt2 = [0,]*len(cnt1)
for i in range(1,len(cnt1)):
    cnt2[i] = cnt1[i] - cnt1[i-1]
cnt2.append(N-sum(cnt2))
word.append(S2[N-1])
for i in range(len(cnt2)):
    if cnt2[i] == max(cnt2):
        print(word[i])

### FIXED CODE ###

N = int(input())
S = list(str(input()) for _ in range(N))
S2 = sorted(S)
cnt1 = [0,]
cnt2 = [0,]*N
word = [0,]
for i in range(N-1):
    if S2[i] != S2[i+1]:
        cnt1.append(i+1)
        word.append(S2[i])
cnt2 = [0,]*len(cnt1)
for i in range(1,len(cnt1)):
    cnt2[i] = cnt1[i] - cnt1[i-1]
cnt2.append(N-sum(cnt2))
word.append(S2[N-1])
X = max(cnt2)
for i in range(len(cnt2)):
    if cnt2[i] == X:
        print(word[i])
### BUGGY CODE ###

n, m = map(int, input().split())
INF = 10**9
a = [[INF]*n for i in range(n)]
hen_m = []
for i in range(m):
    x1, x2 = map(int, input().split())
    x1 -= 1
    x2 -= 1
    hen_m.append([x1, x2])
    a[x1][x2] = 1
    a[x2][x1] = 1
for i in range(n):
    a[i][i] = 0

#ワーシャルフロイド
def warshall(n, c):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                c[j][k] = min(c[j][k], c[j][i] + c[i][k])

ans = 0
# Mの辺を消して、わ～シャルフロイド
for i in range(m):
    b = [i[::] for i in a]
    x1 , x2 = hen_m[i]
    b[x1][x2] = INF
    b[x2][x1] = INF
    warshall(n, b)
    flag = 0
    for j in range(n - 1):
        for k in range(j + 1,n):
            if b[j][k] >= INF:
                flag = 1
                break
        if flag == 1:
            break
    #print(i, flag)
    ans += flag
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
a = [[False]*n for i in range(n)]
hen_m = []
for i in range(m):
    x1, x2 = map(int, input().split())
    x1 -= 1
    x2 -= 1
    hen_m.append([x1, x2])
    a[x1][x2] = True
    a[x2][x1] = True
for i in range(n):
    a[i][i] = True

#ワーシャルフロイド
def warshall(n, c):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                c[j][k] = c[j][k] or (c[j][i] and c[i][k])

ans = 0
# Mの辺を消して、わ～シャルフロイド
for i in range(m):
    b = [i[::] for i in a]
    x1 , x2 = hen_m[i]
    b[x1][x2] = False
    b[x2][x1] = False
    warshall(n, b)
    flag = 0
    for j in range(n - 1):
        for k in range(j + 1,n):
            if not b[j][k]:
                flag = 1
                break
        if flag == 1:
            break
    #print(i, flag)
    ans += flag
print(ans)
### BUGGY CODE ###

a,b,k = [int(i) for i in input().split()]
appear = [0 for i in range(b+1)]

for i in range(a, a+k):
    if i <= b:
        print(i)
    else:
        break
max = b+1-k
if b+1-k<a+k:
    max = a+k
for i in range(max, b+1):
    print(i)
        


### FIXED CODE ###

a,b,k = [int(i) for i in input().split()]

if a+k-1<b-k+1:
    for i in range(a,a+k):
        print(i)
    for i in range(b+1-k, b+1):
        print(i)
else:
    for i in range(a,b+1):
        print(i)
### BUGGY CODE ###

N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
for j in range(N):
    k=a.pop(j)
    mx=a[0]
    for l in range(1,N-1):
        mx=max(mx,a[l])
    print(mx)
    a.insert(j,k)

### FIXED CODE ###

N=int(input())
mx=int(input())
a=[mx]
for i in range(N-1):
    l=int(input())
    a.append(l)
    mx=max(mx,l)
num=a.index(mx)
a.remove(mx)
mx2=a[0]
for j in range(1,N-1):
    mx2=max(mx2,a[j])
for k in range(N):
    if k==num:
        print(mx2)
    else:
        print(mx)
### BUGGY CODE ###

from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l.sort()

    while 1 < len(l):
        for i in range(1, len(l)):
            if l[i]%l[0] == 0:
                l[i] = l[0]
            elif l[i] - l[i-1] == 1:
                print(1)
                return
            else:
                l[i] = l[i]%l[0]
        l = [e for e in l if e != 0]
        l.sort()

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

if __name__ == '__main__':
    fun()


### FIXED CODE ###

from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        #l = [e for e in l if e != 0]
        l = list(set(l))
        l.sort()

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

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

n = int(input())
l = [int(_) for _ in input().split()]
ans = 0
L = [0 for _ in range(1,4000+1)]
s = [0 for _ in range(0,4000+1)]
for k in range(0, n):
    L[l[k]-1] += 1
for x in range(0,4000):
    s[x+1] = s[x] + L[x]

for i in range(0, n-1):
    for j in range(i+1, n):
        exc = 0
        m = abs(l[i] - l[j])
        M = l[i] + l[j]
        if l[i] > m:
            exc += 1
        if l[j] > m:
            exc += 1
        ans += s[M] - s[m] - L[M-1] - exc
print(ans//3)



### FIXED CODE ###

n = int(input())
l = [int(_) for _ in input().split()]
ans = 0
L = [0 for _ in range(1,2000+2)]
s = [0 for _ in range(0,2000+2)]
for k in range(0, n):
    L[l[k]-1] += 1
for x in range(0,2001):
    s[x+1] = s[x] + L[x]
 
for i in range(0, n-1):
    for j in range(i+1, n):
        exc = 0
        m = abs(l[i] - l[j])
        M = l[i] + l[j]
        if l[i] > m:
            exc += 1
        if l[j] > m:
            exc += 1
        ans += s[M] - s[m] - L[M-1] - exc
print(ans//3)
### BUGGY CODE ###

import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le[i], ri[i]))

print(sum(ans))

### FIXED CODE ###

import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le.popleft(), ri.popleft()))

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

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 077 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x):
    global debug
    if debug:
        print(x)


def probC_TLE():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    b = []
    for i in range(N):
        b.append(A[i])
        b.reverse()
        dmp(b)
    return b


def probC_TLE2():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    former, latter = [], []
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = [A[i]] + latter
        else:
            former.append(A[i])
        full = former + latter
        dmp((former, latter, full))
    return full


def probC():
    N = getInt()
    A = [x for x in input().split()]
    dmp((N, A))
    former, latter = '', ''
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = A[i] + ' ' + latter
        else:
            former = former + ' ' + A[i]
        dmp((former, latter))
    return former[1:] + ' ' + latter


debug = False
print(probC())
# for n in probC():
#    print(n, end=' ', flush=True)


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 077 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)


def probC_TLE():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    b = []
    for i in range(N):
        b.append(A[i])
        b.reverse()
        dmp(b)
    return b


def probC_TLE2():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    former, latter = [], []
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = [A[i]] + latter
        else:
            former.append(A[i])
        full = former + latter
        dmp((former, latter, full))
    return full


def probC_TLE3():
    N = getInt()
    A = [x for x in input().split()]
    dmp((N, A))
    former, latter = '', ''
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = A[i] + ' ' + latter
        else:
            former = former + ' ' + A[i]
        dmp((former, latter))
    return former[1:] + ' ' + latter


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    b = zeros(N)
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            b[i//2] = A[i]
        else:
            b[-i//2] = A[i]
        dmp(b)
    return b


debug = False
# print(probC())
for n in probC():
    print(n, end=' ', flush=True)
### BUGGY CODE ###

H, W = map(int, input().split())
N = H * W

chart = [input() for _ in range(H)]

def node(h, w):
    return h * W + w

minDist = [[10**10] * N for _ in range(N)]

for i in range(N):
    minDist[i][i] = 0

for h in range(H):
    for w in range(W):
        if chart[h][w] == '#':
            continue

        if h > 0 and chart[h - 1][w] == '.':
            minDist[node(h, w)][node(h - 1, w)] = 1
            minDist[node(h - 1, w)][node(h, w)] = 1
        if h < H - 1 and chart[h + 1][w] == '.':
            minDist[node(h, w)][node(h + 1, w)] = 1
            minDist[node(h + 1, w)][node(h, w)] = 1
        if w > 0 and chart[h][w - 1] == '.':
            minDist[node(h, w)][node(h, w - 1)] = 1
            minDist[node(h, w - 1)][node(h, w)] = 1
        if w < W - 1 and chart[h][w + 1] == '.':
            minDist[node(h, w)][node(h, w + 1)] = 1
            minDist[node(h, w + 1)][node(h, w)] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d = minDist[i][k] + minDist[k][j]
            if minDist[i][j] > d:
                minDist[i][j] = d

ans = 0
for dists in minDist:
    for d in dists:
        if d < 10**10:
            ans = max(ans, d)

print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
N = H * W

chart = [input() for _ in range(H)]

def node(h, w):
    return h * W + w

minDist = [[10**10] * N for _ in range(N)]

for i in range(N):
    minDist[i][i] = 0

for h in range(H):
    for w in range(W):
        if chart[h][w] == '#':
            continue

        if h > 0 and chart[h - 1][w] == '.':
            minDist[node(h, w)][node(h - 1, w)] = 1
            minDist[node(h - 1, w)][node(h, w)] = 1
        if h < H - 1 and chart[h + 1][w] == '.':
            minDist[node(h, w)][node(h + 1, w)] = 1
            minDist[node(h + 1, w)][node(h, w)] = 1
        if w > 0 and chart[h][w - 1] == '.':
            minDist[node(h, w)][node(h, w - 1)] = 1
            minDist[node(h, w - 1)][node(h, w)] = 1
        if w < W - 1 and chart[h][w + 1] == '.':
            minDist[node(h, w)][node(h, w + 1)] = 1
            minDist[node(h, w + 1)][node(h, w)] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d = minDist[i][k] + minDist[k][j]
            if minDist[i][j] > d:
                minDist[i][j] = d

ans = 0
for dists in minDist:
    for d in dists:
        if d < 10**10:
            ans = max(ans, d)

print(ans)