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

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


yoko, tate = [], []
for h in range(H):
    now = []
    
    w, cnt = 0, 0
    while True:
        if not w < W:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "#":
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        w += 1

    yoko.append(now)

for w in range(W):
    now = []
    
    h, cnt = 0, 0
    while True:
        if not h < H:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "#":
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        h += 1
    
    tate.append(now)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, yoko[h][w]+tate[w][h]-1)
    
print(ans)

### FIXED CODE ###

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


yoko, tate = [], []
for h in range(H):
    now = []
    
    w, cnt = 0, 0
    while True:
        if not w < W:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "#":
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        w += 1

    yoko.append(now)

for w in range(W):
    now = []
    
    h, cnt = 0, 0
    while True:
        if not h < H:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "#":
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        h += 1
    
    tate.append(now)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, yoko[h][w]+tate[w][h]-1)
    
print(ans)
### BUGGY CODE ###

N = int(input())
"""
yとzで残り
"""
from math import sqrt
for n in range(1,N+1):
    cnt = 0
    for x in range(1,int(sqrt(n))+1):
        for y in range(1,int(sqrt(n))+1):
            for z in range(1,int(sqrt(n))+1):
                if x**2+y**2+z**2+x*y+y*z+z*x == n:
                    cnt += 1
    print(cnt)

### FIXED CODE ###

N = int(input())
"""
yとzで残り
"""
memo = {}
from math import sqrt
for x in range(1,int(sqrt(N))+1):
    for y in range(1,int(sqrt(N))+1):
        for z in range(1,int(sqrt(N))+1):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n not in memo:
                memo[n] = 0
            memo[n] += 1

for i in range(1,N+1):
    if i in memo:
        print(memo[i])
    else:
        print(0)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

dp = [0] * (w + 1)

for _ in range(n):
    wi, vi = map(int, input().split())

    for wj in range(w, wi - 1, -1):
        nv = dp[wj - wi] + vi
        if dp[wj] < nv:
            dp[wj] = nv

print(max(dp))


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n, w = map(int, input().split())

    dp = [0] * (w + 1)

    for _ in range(n):
        wi, vi = map(int, input().split())

        for wj in range(w, wi - 1, -1):
            nv = dp[wj - wi] + vi
            if dp[wj] < nv:
                dp[wj] = nv

    print(max(dp))

main()
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7

def main():
	n, m = map(int, input().split())
	*s, = map(int, input().split())
	*t, = map(int, input().split())
	dp = [[1] * (m + 1)] + [[1] + [0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] * (s[i] != t[j])) % mod
	print(dp[n][m])

if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7

def main():
	n, m = map(int, input().split())
	*s, = map(int, input().split())
	*t, = map(int, input().split())
	dp = [[1] * (m + 1)] + [[1] + [0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] * (s[i] != t[j])) % mod
	print(dp[n][m])

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

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect
from itertools import product
from collections import deque

import sys
input = sys.stdin.readline

def solve(h,w,ch,cw,dh,dw,s):
    d = [[10**7]*w for _ in range(h)]
    d[ch][cw] = 0
    dis0 = [(1,0),(0,1),(-1,0),(0,-1)]
    dis1 = [(i,j) for i,j in product(range(-2,3),range(-2,3)) if 1 < abs(i)+abs(j)]
    Q = deque([(ch,cw)])
    ans = -1
    while Q:
        pos1 = Q.pop()
        i, j = pos1
        if i == dh and j==dw:
            ans = d[dh][dw]
            break
        for pos2 in [(i+a,j+b) for a,b in dis0 if 0 <= i+a < h and 0 <= j+b <w and s[i+a][j+b]=="."]:
            k, l = pos2
            alt = d[i][j] 
            if d[k][l] > alt:
                d[k][l] = alt
                Q.append((k,l))
        for pos2 in [(i+a,j+b) for a,b in dis1 if 0 <= i+a < h and 0 <= j+b <w and s[i+a][j+b]=="."]:
            k, l = pos2
            alt = d[i][j]+1
            if d[k][l] > alt:
                d[k][l] = alt
                Q.appendleft((k,l))
    print(ans)



def main():
    h, w = list(map(int,input().split()))
    ch, cw = list(map(int,input().split()))
    dh, dw = list(map(int,input().split()))
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    s = []
    for _ in range(h):
        s.append(list(input().rstrip()))
    solve(h,w,ch,cw,dh,dw,s)


if __name__ == "__main__":
    main()

### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect
from itertools import product
from collections import deque

import sys
input = sys.stdin.readline

def solve(h,w,ch,cw,dh,dw,s):
    d = [[10**7]*w for _ in range(h)]
    d[ch][cw] = 0
    dis0 = [(1,0),(0,1),(-1,0),(0,-1)]
    dis1 = [(i,j) for i,j in product(range(-2,3),range(-2,3)) if 1 < abs(i)+abs(j)]
    Q = deque([(ch,cw)])
    ans = -1
    while Q:
        pos1 = Q.pop()
        i, j = pos1
        if i == dh and j==dw:
            ans = d[dh][dw]
            break
        for pos2 in [(i+a,j+b) for a,b in dis0 if 0 <= i+a < h and 0 <= j+b <w and s[i+a][j+b]=="."]:
            k, l = pos2
            alt = d[i][j] 
            if d[k][l] > alt:
                d[k][l] = alt
                Q.append((k,l))
        for pos2 in [(i+a,j+b) for a,b in dis1 if 0 <= i+a < h and 0 <= j+b <w and s[i+a][j+b]=="."]:
            k, l = pos2
            alt = d[i][j]+1
            if d[k][l] > alt:
                d[k][l] = alt
                Q.appendleft((k,l))
    print(ans)



def main():
    h, w = list(map(int,input().split()))
    ch, cw = list(map(int,input().split()))
    dh, dw = list(map(int,input().split()))
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    s = []
    for _ in range(h):
        s.append(list(input().rstrip()))
    solve(h,w,ch,cw,dh,dw,s)


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

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

c = collections.Counter(A)
ans = 0
len_A=len(set(A))
if(len_A<=K):
    print(ans)
else:
    for i in range(len_A-K):
        ans +=c.most_common()[-1*(i+1)][1]
    print(ans)

### FIXED CODE ###

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

c = collections.Counter(A)
ans = 0
d=c.most_common()
len_A=len(set(A))
if(len_A<=K):
    print(ans)
else:
    for i in range(len_A-K):
        ans +=d[-1*(i+1)][1]
    print(ans)
### BUGGY CODE ###

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

total = 0
for i in range(n):
  for j in range(i+1, n):
    total += int(abs(j-i) == a[i]+a[j])
print(total)

### FIXED CODE ###

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

dict_diffs1 = dict()
dict_diffs2 = dict()
for i in range(1, n+1):
  dict_diffs1[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
  dict_diffs2[i-a[i-1]] = dict_diffs2.get(i-a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
  total += dict_diffs2.get(j+a[j-1], 0)
total = total//2
print(total)
### BUGGY CODE ###

N = int(input())
for n in range(1,3501):
    for w in range(1,3501):
        if 4*n*w-N*(n+w) != 0:
            h = (N*n*w)/(4*n*w-N*(n+w))

            if h > 0 and h.is_integer():
                print(int(h), n, w)
                exit()



### FIXED CODE ###

N = int(input())
for n in range(1,3501):
    for w in range(1,3501):
        if 4*n*w-N*(n+w) != 0:
            h = (N*n*w)/(4*n*w-N*(n+w))

            if h > 0 and h.is_integer():
                print(int(h), n, w)
                exit()
### BUGGY CODE ###

def rec(nums, idx):
    if len(nums) == idx + 1:
        if nums[idx] % 10 == 0:
            return 0
        else:
            return nums[idx]
    A = nums[idx] + rec(nums, idx + 1)
    B = rec(nums, idx + 1)
    if A % 10 == 0:
        A = 0
    if B % 10 == 0:
        B = 0
    return max(A, B)

N = int(input())

nums = []
for i in range(0, N):
    nums.append(int(input()))

print(str(rec(nums, 0)))

### FIXED CODE ###

N = int(input())

nums = []
max = 0

for i in range(0, N):
    nums.append(int(input()))

mx = sum(nums)
if mx % 10 != 0:
    print(str(mx))
    quit()

checker = [False for i in range(0, mx+1)]

now = 0
res = 0
for i in range(0, N):
    v = nums[i]
    for j in range(now, -1, -1):
        if checker[j]:
            idx = j + v
            if idx > res and idx % 10 != 0:
                res = idx
            checker[idx] = True
    checker[v] = True
    now = now + v

print(str(res))
### BUGGY CODE ###

N = int(input())
res = 0
for i in range(N):
    res += i

print(res)

### FIXED CODE ###

N = int(input())
N -= 1
print(N*(N+1)//2)
### BUGGY CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    B = set(A)
    for i in B:
        L.append(A.count(i))
    L.sort()
    if len(B) <= K:
        print('0')
    else:
        print(str(sum(L[0:len(B)-K])))


if __name__ == "__main__":
    main()



### FIXED CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = set(A)
    L = [0 for i in range(N+1)]
    for i in A:
        L[i] += 1
    L.sort()
    if len(B) <= K:
        print('0')
    else:
        print(str(sum(L[0:N+1-K])))


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


def chousa(b):
    poped = ["x"]*len(b)
    a = []
    isnt_sorted = len(b)
    while isnt_sorted:
        for i,v in enumerate(b[::-1]):
            if v == 1 and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break
            elif len(a) >= v-1 and a[v-2][0] < len(b)-i and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break

        print(v)
def main():
    N = int(input())
    b = list(map(int,input().split()))
    chousa(b)
if __name__ == "__main__":
    main()

### FIXED CODE ###


def chousa(b):
    poped = ["x"]*len(b)
    a = []
    isnt_sorted = len(b)
    for i,v in enumerate(b[::-1]):
        if len(b)-i < v:
            print(-1)
            return

    while isnt_sorted:
        for i,v in enumerate(b[::-1]):
            if v == 1 and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break
            elif len(a) >= v-1 and a[v-2][0] < len(b)-i and poped[len(b)-i-1] == "x":
                a.insert(v-1, [len(b)-i,v])
                poped[len(b)-i-1] = "o"
                isnt_sorted -= 1
                break

        print(v)
def main():
    N = int(input())
    b = list(map(int,input().split()))
    chousa(b)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
s = input()
flag = 0
for i in range(int(input())):
	X = sys.stdin.readline().split()
	if int(X[0]) == 1:
		flag = flag^1	
	elif (int(X[1])-1)^flag == 0:
		s = X[2] + s
	else:
		s = s + X[2]
if flag == 1:
	print(s[::-1])
else:
	print(s)


### FIXED CODE ###

import sys
s = input()
flag = 0
s1 = ""
s2 = ""

for i in range(int(input())):
	X = sys.stdin.readline().split()
	if int(X[0]) == 1:
		flag = flag^1	
	elif (int(X[1])-1)^flag == 0:
		s1 += X[2]
	else:
		s2 += X[2]
s3 = s1[::-1]+s+s2
if flag:
	print(s3[::-1])
else:
	print(s3)
### BUGGY CODE ###

def main():
    S = list(input())
    Q = int(input())
    l = [list(input().split(' ')) for _ in range(Q)]

    FLAG = False

    for li in l:
        if int(li[0]) == 1: # 前後反転
            if FLAG == True:
                FLAG = False
            else:
                FLAG = True
        
        elif int(li[0]) == 2: # 追加, li[1] == 1 => li[2]を先頭に，li[1] == 2 => li[2]を末尾
            if int(li[1]) == 1:
                if FLAG == True:
                    S.append(li[2])
                else:
                    S.insert(0, li[2])
            elif int(li[1]) == 2:
                if FLAG == True:
                    S.insert(0, li[2])
                else:
                    S.append(li[2])
                    
                # S.append(li[2])
        # print(S)
    if FLAG:
        S = S[::-1]
    print(''.join(S))


main()

### FIXED CODE ###

from collections import deque

def main():
    S = list(input())
    Q = int(input())
    l = [list(input().split(' ')) for _ in range(Q)]

    d = deque(S)

    FLAG = False

    for li in l:
        if int(li[0]) == 1: # 前後反転
            if FLAG == True:
                FLAG = False
            else:
                FLAG = True
        
        elif int(li[0]) == 2: # 追加, li[1] == 1 => li[2]を先頭に，li[1] == 2 => li[2]を末尾
            if int(li[1]) == 1:
                if FLAG == True:
                    d.append(li[2])
                else:
                    d.appendleft(li[2])
            elif int(li[1]) == 2:
                if FLAG == True:
                    d.appendleft(li[2])
                else:
                    d.append(li[2])

    S = ''.join(d)
    if FLAG:
        S = S[::-1]
    print(S)


main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

def main():
    n,k = map(int, input().split())
    l = list(map(int, input().split()))
    out = 0
    out_i = 0

    for i in range(len(l)-(k-1)):
        result = 0
        s = sum(l[i:i+k])

        if out < s:
            out = s
            out_i = i

    r = sum(map(mean, l[out_i:out_i+k]))
    print(r)

def mean(x):
    x = x
    return sum(range(x+1))/x

if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-

def main():
    n,k = map(int, input().split())
    l = list(map(mean, input().split()))
    out = sum(l[:k])
    result = out

    for i in range(1, len(l)-(k-1)):
        result = result - l[i-1] + l[i+k-1]

        if out < result:
            out = result

    print(out)

def mean(x):
    x = int(x)
    return x * (x+1) / (2 * x)

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

import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

N = ni()
x = nal()
x.insert(0, 0)

n = 1
c = 0
a = 1

for i in range(N):
    t = x[i+1] - x[i] - 1
    c = c+1
    if(t > 1):
        n = n+t-1
    elif(t == 0):
        n = n-1
        if(n == -1):
            n = 1
            a = a*c
            c = c-1

for i in range(1, c+1):
    a = a*i

print(a % INF)

### FIXED CODE ###

import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

N = ni()
x = nal()
x.insert(0, 0)

n = 1
c = 0
a = 1

for i in range(N):
    t = x[i+1] - x[i] - 1
    c = c+1
    if(t > 1):
        n = n+t-1
    elif(t == 0):
        n = n-1
        if(n == -1):
            n = 1
            a = a*c%INF
            c = c-1

for i in range(1, c+1):
    a = a*i%INF

print(a % INF)
### BUGGY CODE ###

N = int(input())
tmp = input()
a_list = []
for i in range(N):
    a_list.append(int(tmp.split(' ')[i]))

count = 0
for l in a_list:
    tmp_l = l
    while(tmp_l % 2 == 0):
        count += 1
        tmp_l = tmp_l / 2

print(count)


### FIXED CODE ###

import math
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
  while a[i] % 2 == 0:
    ans += 1
    a[i] = a[i] // 2
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    num = a.index(max(a))
    a[num] = max(a) // 2
print(sum(a))

### FIXED CODE ###

from heapq import heappop,heappush,heapify

N, M = map(int, input().split())
A = list(map(int, input().split()))
A_minus = [-a for a 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 ###

import numpy as np
P=998244353
N,K=map(int,input().split())
LR=[]
for _ in range(K):
  l,r=map(int,input().split())
  LR+=range(l,r+1)
LR=list(set(LR))
LR=np.array(LR)
c=[0]*N
c[0]=1
for k in range(N):
  S=list(LR[LR<=k])
  while len(S):
    c[k]+=c[k-S[-1]]%P
    S.pop()
print(c[-1]%P)

### FIXED CODE ###

P=998244353
N,K=map(int, input().split())
LR=[list(map(int, input().split())) for _ in range(K)]

s=[0 for _ in range(N+1)]
s[1]=1
for i in range(1,N):
  s[i+1] = s[i]
  for l,r in LR:
    s[i+1]+=(s[max(0,i-l+1)]-s[max(0,i-r)])%P
    s[i+1]%=P
print((s[N]-s[N-1])%P)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    string = int(input())
    if a.count(string) == 0:
        a.append(string)
    else:
        a.remove(string)
print(len(a))


### FIXED CODE ###

import sys
import collections
import bisect


def main():
    n = int(input())
    A = [int(input()) for _ in range(n)]
    c = collections.Counter(A)
    sumA = 0
    cKeys = c.keys()
    for cKey in cKeys:
        sumA += c[cKey] % 2
    print(sumA)


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

# -*- coding: utf-8 -*-
from sys import stdin
from bisect import bisect_left

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = ds_in()

A_list.sort()

ans = 0
while len(A_list) > 1:
    max_a = A_list.pop()
    if bin(max_a)[3:].find('1') == -1:
        if max_a == A_list[-1]:
            A_list.pop()
            ans += 1
    else:
        cand = 2 ** len(bin(max_a)[2:]) - max_a
        idx = bisect_left(A_list, cand)
        if idx < len(A_list) and cand == A_list[idx]:
            A_list.pop(idx)
            ans += 1

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
from collections import Counter

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = np.array(ds_in())
A_list.sort()
EPSILON = 10**(-6)

cand_A = 2 ** (np.log2(A_list + EPSILON).astype(int) + 1) - A_list
idx = np.searchsorted(A_list, cand_A)
A_count = dict(Counter(A_list))

ans = 0
for i in range(N-1, -1, -1):
    if A_count[A_list[i]] <= 0:
        continue
    A_count[A_list[i]] -= 1
    if (A_list[idx[i]] == cand_A[i]) and (A_count[cand_A[i]] > 0):
        ans += 1
        A_count[cand_A[i]] -= 1

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

a = set()
for _ in range(int(input())):
    a ^= {input()}
print(len(a))

### FIXED CODE ###

a = set()
for _ in range(int(input())):
    a ^= {input()}
print(len(a))
### BUGGY CODE ###

def main():
  N=int(input())
  P=list(map(int,input().split()))
  sFlag=True
  i=0
  sumCount=0
  for i in range(N):
    Pi=P[i]
    Pj=min(P[0:i+1])
    if(Pi<=Pj):
      sumCount=sumCount+1
  print(sumCount)
if __name__ == '__main__':
  main()

### FIXED CODE ###

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

num = p[0]
ans = 1

for i in range(1, n):
    if num >= p[i]:
        ans += 1
        num = p[i]

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

n=int(input())
s=[int(input()) for _ in range(5)]
t1=[n if _==0 else 0 for _ in range(6)]
t2=[n if _==5 else 0 for _ in range(6)]
c=0
while True:
    for i in range(5):
        if t1[-i-2]>s[-i-1]:
            t1[-i-1]+=s[-i-1]
            t1[-i-2]-=s[-i-1]
        else:
            t1[-i-1]+=t1[-i-2]
            t1[-i-2]=0

    #print(t1)


    c+=1

    if t1==t2:
        break
print(c)


### FIXED CODE ###

import math
n=int(input())
x=[int(input()) for i in range(5)]

m=0
for i in range(5):
    if x[m]>x[i]:
        m=i
if m==0:
    print(5+math.ceil(n/x[0])-1)
else:
    print(5+math.ceil(n/x[m])-1)
### BUGGY CODE ###

from collections import deque
import numpy as np
h, w = map(int, input().split())
mass = [[ord(i) for i in input()] for _ in range(h)]
wall = ord("#")
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]


def bfs(s, t):
    if mass[s][t] == wall:
        return 0
    visited = np.zeros((h, w))
    depth = np.zeros((h, w))
    q1 = deque([s])
    q2 = deque([t])
    while q1:
        x = q1.popleft()
        y = q2.popleft()
        visited[x][y] += 1

        for d in range(4):
            nx = x + dx[d]
            ny = y + dy[d]
            if nx < 0 or h - 1 < nx or ny < 0 or w - 1 < ny:
                continue

            if mass[nx][ny] == wall or visited[nx][ny]:
                continue

            q1.append(nx)
            q2.append(ny)
            depth[nx][ny] = depth[x][y] + 1
    return np.max(depth)


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(int(ans))


### FIXED CODE ###

import numpy as np
from collections import deque
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]


def dist(s, t):
    if r[s][t] == "#":
        return 0
    else:
        visited = np.zeros((h, w))
        visited[s][t] += 1
        distance = np.zeros((h, w))
        q = deque([[s, t]])
        while len(q) > 0:
            i, j = q.popleft()
            d = distance[i][j] + 1
            if j != w-1:
                if r[i][j+1] == "." and not visited[i][j+1]:
                    q.append([i, j + 1])
                    visited[i][j+1] += 1
                    distance[i][j+1] += d
            if j != 0:
                if r[i][j-1] == "." and not visited[i][j-1]:
                    q.append([i, j - 1])
                    visited[i][j - 1] += 1
                    distance[i][j - 1] += d
            if i != 0:
                if r[i-1][j] == "." and not visited[i-1][j]:
                    q.append([i - 1, j])
                    visited[i-1][j] += 1
                    distance[i-1][j] += d
            if i != h-1:
                if r[i+1][j] == "." and not visited[i+1][j]:
                    q.append([i + 1, j])
                    visited[i+1][j] += 1
                    distance[i+1][j] += d
        return np.max(distance)


ans = 0
for s in range(h):
    for t in range(w):
        ans = max(ans, dist(s, t))

print(int(ans))