Harryxun/stf_run huggingface dataset:
from collections import deque
H, W = map(int,input().split())

A = [[False for _ in range(W)] for _ in range(H)]

Q = deque()
for y in range(H):
    S = input()
    for x, a in enumerate(S):
        if a == "#":
            Q.append((x, y))
            A[y][x] = True

ans = 0
while True:
    ans += 1
    NQ = deque()
    while Q:
        x, y = Q.pop()
        if y != 0 and A[y-1][x] == False:
            A[y-1][x] = True
            NQ.append((x,y-1))
        if y != H-1 and A[y+1][x] == False:
            A[y+1][x] = True
            NQ.append((x,y+1))
        if x != 0 and A[y][x-1] == False:
            A[y][x-1] = True
            NQ.append((x-1,y))
        if x != W-1 and A[y][x+1] == False:
            A[y][x+1] = True
            NQ.append((x+1,y))
    if NQ:
        Q = NQ.copy()
    else:
        break

print(ans-1)

### FIXED CODE ###

def main():
    H, W = map(int,input().split())

    A = [[False for _ in range(W)] for _ in range(H)]

    Q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                Q.append((y, x))
                A[y][x] = True

    ans = 0
    while Q:
        ans += 1
        NQ = []
        for y, x in Q:
            if x > 0 and A[y][x-1] == False:
                A[y][x-1] = True
                NQ.append((y,x-1))
            if x < W-1 and A[y][x+1] == False:
                A[y][x+1] = True
                NQ.append((y,x+1))
            if y > 0 and A[y-1][x] == False:
                A[y-1][x] = True
                NQ.append((y-1, x))
            if y < H-1 and A[y+1][x] == False:
                A[y+1][x] = True
                NQ.append((y+1,x))
        if NQ:
            Q = NQ
        else:
            break

    print(ans-1)

if __name__ == '__main__':
    main()
time=int(input())
sec=time%60
min=(time/60)%60
hour=time/3600
print(hour : min : sec)

### FIXED CODE ###

time=int(input())
sec=time%60
min=(time//60)%60
hour=time//3600
print(hour,min,sec,sep=':')
int x = input()
print(x * x * x)

### FIXED CODE ###

x = int(input())
print(x ** 3)
n = int(input())

nlll = {}
    
for i in range(n):
    aaa = int(input())
    if nlll in aaa:
        del aaa
    else:
        nlll.update({aaa:1})

sums = 0
for i in nlll.values():
    sums = sums + i
print(sums)

### FIXED CODE ###

n = int(input())

nlll = {}
    
for i in range(n):
    aaa = int(input())
    if aaa in nlll:
        del nlll[aaa]
    else:
        nlll.update({aaa:1})

sums = 0
for i in nlll.values():
    sums = sums + i
print(sums)
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 7
L = 15
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            ab[i - j + OFFSET] = False # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and c[i] != '?' and b[j] != '?':
            bc[i - j + OFFSET] = False # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L): # Bの左端をずらす
    for j in range(L): # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)


### FIXED CODE ###

a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 4000
L = 8001
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            k = i - j + OFFSET
            ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and b[i] != '?' and c[j] != '?':
            bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L):  # Bの左端をずらす
    for j in range(L):  # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)
k = int(input())
s = input()
        
length = len(s)
if length > K:
    s = s[:K]+"..."
print(s)


### FIXED CODE ###

k = int(input())
s = input()
        
length = len(s)
if length > k:
    s = s[:k]+"..."
print(s)
N = int(input())
S = input()

ans = 0
tmp = [0 for _ in range(10)]
for i in range(len(S)):
    tmp[int(S[i])] += 1

for i in range(1000):
    flag = True

    if i < 10:
        dic = {"0": 2}
    elif i < 100:
        dic = {"0": 1}
    else:
        dic = {}
    for j in range(len(str(i))):
        if str(i)[j] in dic:
            dic[str(i)[j]] += 1
        else:
            dic[str(i)[j]] = 1

    for k, v in dic.items():
        if dic[k] > tmp[int(k)]:
            flag = False
            break

    if flag:
        t = 0
        for j in range(len(S)):
            if str(i)[t] == S[j]:
                t += 1
            if t == 3:
                ans += 1
                break

print(ans)



### FIXED CODE ###

N = int(input())
S = input()

ans = 0
tmp = [0 for _ in range(10)]
for i in range(len(S)):
    tmp[int(S[i])] += 1

for i in range(1000):
    flag = True

    if i < 10:
        dic = {"0": 2}
    elif i < 100:
        dic = {"0": 1}
    else:
        dic = {}
    for j in range(len(str(i))):
        if str(i)[j] in dic:
            dic[str(i)[j]] += 1
        else:
            dic[str(i)[j]] = 1

    for k, v in dic.items():
        if dic[k] > tmp[int(k)]:
            flag = False
            break

    if flag:
        if i < 10:
            tmp_i = "00" + str(i)
        elif i < 100:
            tmp_i = "0" + str(i)
        else:
            tmp_i = str(i)
        t = 0
        for j in range(len(S)):
            if tmp_i[t] == S[j]:
                t += 1
            if t == 3:
                ans += 1
                break

print(ans)
# sys.stdin.readline()
import sys
import time
input = sys.stdin.readline
import math

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
# A.sort(reverse=True)

# t1 = time.time()
for i in range(M):
    a = max(A) // 2
    j = A.index(max(A))
    A[j] = a
	if sum(A) <1:
		break

print(sum(A))

### FIXED CODE ###

# sys.stdin.readline()
import sys
import time
input = sys.stdin.readline
import math
import heapq

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
A = [-i for i in A]
# print(A)
heapq.heapify(A)
# print(heapq.heappop(A))

# t1 = time.time()
for i in range(M):
    a = -heapq.heappop(A) // 2
    heapq.heappush(A, -a)
    # j = A.index(max(A))
    # A[j] = a
    # A[0] = A[0]//2
    # A.sort(reverse=True)
    # if sum(A) <1:
    #     break

print(-sum(A))
s=input()
k=int(input())

li=[]
if len(s)<=k:
    iif=0
else:
    iif=k
for i in range(len(s)):
    for j in range(1, len(s)-iif+1):
        li.append(s[i:i+j])
        #print(s[i:i+j])

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])

### FIXED CODE ###

s=input()
k=int(input())

li=[]
for i in range(len(s)):
    for j in range(1, k+1):
        li.append(s[i:i+j])

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])
a,b=map(int,input().split())
print("GRATER" if a>b else "LESS" if a<b else "EQUAL")

### FIXED CODE ###

a,b=[list(input()) for i in range(2)]
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
elif a>b:
  print("GREATER")
elif a<b:
  print("LESS")
else:
  print("EQUAL")
n, sum = map(int, input().split())

for x in range(n + 1):
    for y in range(n - x + 1):
        if x * 10000 + y * 5000 + (n-x-y) * 1000 == sum:
            print(f'{x} {y} {n-x-y}')
            exit()

print('-1 -1 -1')

### FIXED CODE ###

n=int(input())
d=list(map(int, [input() for i in range(n)]))
print(len(set(d)))
A, B, N = map(int, input().split())
if N < B:
    print(A*N//B)
else:
    l = [(A*i//B)-(A*(i//B)) for i in range(abs(N-5), N+1)]
    print(max(l))

### FIXED CODE ###

K = int(input())
A, B = map(int, input().split())
result = 'NG'
for i in range (A, B + 1):
    if i % K == 0:
        result = 'OK'
print(result)
def( a , b )

ans1 = a * b
ans2 = 2 * ( a + b )

print ans1 ans2

### FIXED CODE ###

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

ans1 = a * b
ans2 = 2 * ( a + b )

print ans1 , ans2
s,t=input().split(' ')
a,b=map(int,input().split())
u=input()
if u==s:
  a=a-1
if u==t:
  b=b-1
print(a+' '+b)

### FIXED CODE ###

s,t=input().split(' ')
a,b=map(int,input().split())
u=input()
if u==s:
    a=a-1
if u==t:
    b=b-1
print(str(a)+' '+str(b))
for i in range(1, a):
    if a % i == 0:
        li.append(i)
    else:
        continue

for i in range(1, b):
    if b % i == 0:
        li.append(i)
    else:
        continue

li2 =[]
for n in range(len(li)):
    if li.count(li[n]) == 2:
        li[n] = num
        li2.append(num)
        li.remove(num)
        li.remove(num)
    else:
        continue

li2.sort(reverse=True)
print(li2[k-1])

### FIXED CODE ###

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

def ooo(x):
    lix =[]
    for i in range(1, x+1):
        if x % i == 0:
            lix.append(i)
    return lix

lia = ooo(a)
lib = ooo(b)
li = lia + lib

li2 =[]
for n in range(len(li)):
    if not li[n] in li2: 
        if li.count(li[n]) == 2:
            li2.append(li[n])

li2.sort(reverse=True)
print(li2[k-1])
def close(v, i):
    j = int(s[v] == 'B')
    for u in links[v][i].copy():
        links[u][j].remove(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    la, lb = links[a], links[b]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)
    i, j = [(0, 1), (1, 0)][s[a] == 'B']
    if not lb[i] and lb[j]:
        able[b] = True
    lb[i].add(a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print('Yes' if any(able) else 'No')


### FIXED CODE ###

import sys

sys.setrecursionlimit(200000)


def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)


def close(v, i):
    j = int(s[v] == 'B')
    for u in links[v][i].copy():
        if not able[u]:
            continue
        links[u][j].discard(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print('Yes' if any(able) else 'No')
n = int(input())

used = [empty]
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
        
        past = t
    else:
        t = str(input())
        for j in used:
            if j == t:
                ans = "No"
    
    if past[-1] != t[1]:
        ans = "No"
    used.append(t)
    past = t

print(ans)

    
    


### FIXED CODE ###

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

for i in range(1,3):
    if ((a*b*i)%2) == 1:
        c = 1

if c == 1:
    print("Yes")
else:
    print("No")
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


COST = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6
}


# inputs
N, M = 0, 0
A = [0]


def hoge():
    d = dict()
    def labeler(label, iter):
        enumerate()


def set_inputs():
    global N, M, A
    N, M = get_int_list()
    A = get_int_list()


@lru_cache(maxsize=None)
def dp(i):
    if i < min(COST[a] for a in A):
        return 0
    return max(dp(i - COST[a]) + 1 for a in A)


def main():
    set_inputs()

    candidates = sorted(A, reverse=True)
    ret = []
    n = N
    for i in range(dp(N)):
        for a in candidates:
            cond = True
            if i == dp(N) - 1:
                cond = COST[a] == n
            if dp(n - COST[a]) == dp(n) - 1 and cond:
                ret.append(a)
                n -= COST[a]
                break
    print(''.join(str(r) for r in ret))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


COST = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6
}


# inputs
N, M = 0, 0
A = [0]


def hoge():
    d = dict()
    def labeler(label, iter):
        enumerate()


def set_inputs():
    global N, M, A
    N, M = get_int_list()
    A = get_int_list()


@lru_cache(maxsize=None)
def dp(i):
    if i < 0:
        return -inf
    elif i == 0:
        return 0
    return max(dp(i - COST[a]) + 1 for a in A)


def main():
    setrecursionlimit(100000)
    set_inputs()

    candidates = sorted(A, reverse=True)
    ret = []
    n = N
    for i in range(dp(N)):
        for a in candidates:
            cond = True
            if i == dp(N) - 1:
                cond = COST[a] == n
            if dp(n - COST[a]) == dp(n) - 1 and cond:
                ret.append(a)
                n -= COST[a]
                break
    print(''.join(str(r) for r in ret))


if __name__ == '__main__':
    main()
x = 0
while x == 0:

 m = map(int,raw_input().split())

 if m[0] == 0 and m[1] == 0:
     break

 for i in xrange(m[0]):
    print "#" * m[1]
 print ""

### FIXED CODE ###


n = input()
m = map(int,raw_input().split())
a = 0
for i in xrange(n):
    a += m[i]

print min(m),max(m),a
# D - Factorization

N, M = map(int, input().split())
MOD = 10**9 + 7

def prime_factorization(n):
    prime_factors = []
    if n < 2:
        return 0
    for i in range(2, int(pow(n, 0.5)+1)):
        if n%i==0:
            ex = 0
            while n%i==0:
                ex += 1
                n //= i
            prime_factors.append((i, ex))
    if n!=1:
        prime_factors.append((n,1))
    return prime_factors

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+36):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

primes = prime_factorization(M)
ans = 1
for p, ex in primes:
    ans = (ans * comb_mod(ex+N-1, N-1, MOD)) % MOD

print(ans)

### FIXED CODE ###

# D - Factorization

N, M = map(int, input().split())
MOD = 10**9 + 7

def prime_factorization(n):
    prime_factors = []
    if n < 2:
        return 0
    for i in range(2, int(pow(n, 0.5)+1)):
        if n%i==0:
            ex = 0
            while n%i==0:
                ex += 1
                n //= i
            prime_factors.append((i, ex))
    if n!=1:
        prime_factors.append((n,1))
    return prime_factors

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+36):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

primes = prime_factorization(M)
ans = 1
if primes != 0:
    for (p, ex) in primes:
        ans = (ans * comb_mod(ex+N-1, N-1, MOD)) % MOD

print(ans)
n=int(input())

a=input().split()


for i in range(n):
    out=a[(n-i)]
    print(str(out))
print()


### FIXED CODE ###

n=int(input())

a=input().split()

b=[]
for i in range(n):
    out=a[(n-i-1)]
    b.append(out)
print(" ".join(map(str, b)))
def main():
    MOD = 1_000_000_007
    N, M = map(int, input().split())
    a = [int(input()) for _ in range(M)]
    table = [1]*(N+1)
    for broken in a:
        table[broken] = 0
    table[1] = table[0] * table[1]
    for n in range(2, N+1):
        table[n] = ((table[n-2] + table[n-1]) * table[n]) % MOD
    print(table[-1])
main()

### FIXED CODE ###

def main():
    MOD = 1000000007
    N, M = map(int, input().split())
    a = [int(input()) for _ in range(M)]
    table = [1]*(N+1)
    for broken in a:
        table[broken] = 0
    table[1] = table[0] * table[1]
    if N > 1:
        for n in range(2, N+1):
            table[n] = ((table[n-2] + table[n-1]) * table[n]) % MOD
    print(table[-1])
main()
a,b,c=map(int,input.split())
print(b+min(a+b+1,c))

### FIXED CODE ###

a,b,c = map(int,input().split())
print(b + min(a+b+1,c))
A, B, X = map(int, input().split())
lb = -1
ub = X

while ub - lb > 1:
    mid = (lb + ub) // 2
    if A*mid + B*len(str(mid)) > X:
        ub = mid
    else:
        lb = mid
print(min(10**9,lb))

### FIXED CODE ###

#a,b = map(int,input().split())
s = input()
S = ['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-S.index(s))
from collections import deque
N,M,K=map(int,input().split())
A=deque(map(int,input().split()))
B=deque(map(int,input().split()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.pop(0)
        else:
            B.pop(0)
        ans+=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.pop(0)
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.pop(0)
            ans+=1
    if count>K:
        ans-=1
    print(ans)




    
















        


























            
    


    


    
    














    


    














### FIXED CODE ###

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
b=0
for i in range(M):
    b+=B[i]
    if b<=K:
        c+=1
    else:
        break
a=0
b=sum(B)
j=M
ans=0
for i in range(N):
    a+=A[i]
    if a>K:
        break
    while a+b>K:
        b-=B[-1]
        B.pop(-1)
        j-=1
    ans=max(ans,i+j+1)
ans=max(ans,c)
print(ans)
n,x,m=map(int,input().split())

if x==0:
    print(0)
elif m==1:
    print(0)
elif n<=m*3:
    asum=x
    ai=x
    for i in range(1,n):
        ai=(ai*ai)%m
        asum+=ai
    print(asum)
    
else:
    aa=[]
    ai=x
    icnt=0
    asum=0
    while not ai in aa:
        asum+=ai
        aa.append(ai)
        ai=(ai*ai)%m
        icnt+=1
    asum0=0
    ai0=x
    icnt0=0
    for i in range(m):
        asum0+=ai0
        ai0=(ai0*ai0)%m
        icnt0+=1
        if ai0==ai:
            break
    icntk=icnt-icnt0
    n0=n-1-icnt0
    nk=n0//icntk
    nr=n0%icntk
    asumk=asum-asum0
    asumr=0
    air=ai
    for i in range(nr):
        asumr+=air
        air=(air*air)%m
    asumr+=air
       
    ans=asum0+asumk*nk+asumr    
    print(ans)       
        


### FIXED CODE ###


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

if x==0:
    print(0)
elif x==1:
    print(n)
elif m==1:
    print(0)
elif n<=m*2:
    asum=x
    ai=x
    for i in range(1,n):
        ai=(ai*ai)%m
        asum+=ai
    print(asum)
    
else:
    aa=[]
    ai=x
    icnt=0
    asum=0
    while not ai in aa:
        asum+=ai
        aa.append(ai)
        ai=(ai*ai)%m
        icnt+=1
    asum0=0
    ai0=x
    icnt0=0
    if ai!=x:
        for i in range(icnt+1):
            asum0+=ai0
            ai0=(ai0*ai0)%m
            icnt0+=1
            if ai0==ai:
                break
    icntk=icnt-icnt0
    if icntk==0:
#        print("0:",ai,asum,icnt,ai0,asum0,icnt0)
        icntk=1
        n0=n-1
        nk=n0//icntk
        nr=0
        asumk=ai0
        asumr=0
        ans=asum0+x*(n-icnt0)
        print(ans)       
    else:
#        print("1:",ai,asum,icnt,ai0,asum0,icnt0)
        n0=n-1-icnt0
        nk=n0//icntk
        nr=n0%icntk
        asumk=asum-asum0
        asumr=0
        air=ai
        for i in range(nr):
            asumr+=air
            air=(air*air)%m
        asumr+=air
       
        ans=asum0+asumk*nk+asumr    
        print(ans)
N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
        DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)

### FIXED CODE ###

import sys

N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]
sys.setrecursionlimit(N+M)

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
            DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)
import sys

X,N = map(int,input().split())
P = list(map(int,input().split()))
if X < 1 or 100 < X:
    sys.exit()
if N < 0 or 100 < N:
    sys.exit()
if N == 0:
    print(X)
    sys.exit()

P_number = len(P)
if P_number < 1 or 100 < P_number:
    sys.exit()

res1 = 100
res2 = 100
res0 = 0
i = 0
j = 0
while i <= N:
    if (X - i) not in P:
        res1 = (X - i)
        break
    i += 1
while j <= N:
    if (X + j) not in P:
        res2 = (X + j)
        break
    j += 1
if i > j:
    res0 = res2
elif j > i:
    res0 = res1
elif i == j:
    res0 = res1
print(res0)


### FIXED CODE ###

X = list(map(int, input().split()))
count = 1
for I in X:
  if I == 0:
    print(count)
    exit
  count += 1
s = int(input())

if s == 1 or s == 2:
    print(4)
elif:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        
    







        



### FIXED CODE ###

s = int(input())

if s == 1 or s == 2:
    print(4)
else:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1