Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


H, W = map(int, input().split())
start_i, start_j = map(lambda x: int(x) - 1, input().split())
goal_i, goal_j = map(lambda x: int(x) - 1, input().split())
field = [list(input()) for _ in range(H)]

# 1. bfs でワープなしで到達できるマスを探索
# 2. 1 で見つかったマスから一回ワープして到達できるマスを探索
# 3. 1, 2 を繰り返す


walk = [(1, 0), (0, 1), (-1, 0), (0, -1)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]


def bfs(que, warp_times):
    while que:
        i, j, times = que.popleft()
        # ワープ無しで到達できるマスの探索
        for di, dj in walk:
            i_adj, j_adj = i + di, j + dj
            if 0 <= i_adj < H and i <= j_adj < W and field[i_adj][j_adj] == '.':
                if warp_times[i_adj][j_adj] > times:
                    warp_times[i_adj][j_adj] = times
                    que.appendleft((i_adj, j_adj, times))

        # ワープ有りで到達できるマスの探索
        for di, dj in warp:
            i_adj, j_adj = i + di, j + dj
            if 0 <= i_adj < H and i <= j_adj < W and field[i_adj][j_adj] == '.':
                if warp_times[i_adj][j_adj] > times + 1:
                    warp_times[i_adj][j_adj] = times + 1
                    # ワープ無しで到達できるマスを探索しきった後に探索するため、単に append
                    que.append((i_adj, j_adj, times + 1))


warp_times = [[INF for j in range(W)] for i in range(W)]
que = deque()

warp_times[start_i][start_j] = 0
que.append((start_i, start_j, 0))

bfs(que, warp_times)

ans = warp_times[goal_i][goal_j] if warp_times[goal_i][goal_j] < INF else '-1'
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

from collections import deque

INF = 10 ** 12


H, W = map(int, input().split())
s_i, s_j = map(lambda x: int(x) - 1, input().split())
t_i, t_j = map(lambda x: int(x) - 1, input().split())
field = [input() for _ in range(H)]

# 1. bfs でワープなしで到達できるマスを探索
# 2. 1 で見つかったマスから一回ワープして到達できるマスを探索
# 3. 1, 2 を繰り返す


walk = [(1, 0), (0, 1), (-1, 0), (0, -1)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

warp_times = [[INF for j in range(W)] for i in range(H)]
que = deque()

warp_times[s_i][s_j] = 0
que.append((s_i, s_j, 0))

while que:
    i, j, times = que.popleft()
    # ワープ無しで到達できるマスの探索
    for di, dj in walk:
        i_adj, j_adj = i + di, j + dj
        if 0 <= i_adj < H and 0 <= j_adj < W and field[i_adj][j_adj] == '.':
            if warp_times[i_adj][j_adj] > times:
                warp_times[i_adj][j_adj] = times
                que.appendleft((i_adj, j_adj, times))

    # ワープ有りで到達できるマスの探索
    for di, dj in warp:
        i_adj, j_adj = i + di, j + dj
        if 0 <= i_adj < H and 0 <= j_adj < W and field[i_adj][j_adj] == '.':
            if warp_times[i_adj][j_adj] > times + 1:
                warp_times[i_adj][j_adj] = times + 1
                # ワープ無しで到達できるマスを探索しきった後に探索するため、単に append
                que.append((i_adj, j_adj, times + 1))

ans = warp_times[t_i][t_j] if warp_times[t_i][t_j] < INF else '-1'
print(ans)
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1]-a[i]==1:
    b+=c[a[i]-1]
print(total)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1]-a[i]==1:
    b+=c[a[i]-1]
print(b)
a = list(input())
b = list(input())

ans = []

for i in range(len(a)):
    ans.append(a[i])
    if b[i]:
        ans.append(b[i])
print(''.join(ans))

### FIXED CODE ###

s1=input()

s2=input()

ans = []

for i in range(len(s1)+len(s2)):
    if i%2==0:
        ans.append(s1[i//2])
    else:
        ans.append(s2[i//2])

print(''.join(map(str,ans)))
n,m=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
cnt=0
i=0
for _ in range(m):
    if i==len(a): i=0
    a[i]//=2
    if a[i]<a[i+1]: i+=1
print(sum(a))

### FIXED CODE ###

import heapq as hp

n,m=map(int,input().split())
a=list(map(lambda x: -x ,map(int,input().split())))
hp.heapify(a)
for _ in range(m):
    tmp=hp.heappop(a)
    tmp//=-2
    hp.heappush(a,-tmp)
print(-sum(a))
data = input().split()

i = [int(n) for n in data]

print(f"{i[2]} {i[0]} {i[1]}")


### FIXED CODE ###

data = input().split()
i = [int(n) for n in data]
res = "{} {} {}"
print(res.format(i[2], i[0], i[1]))
A = list(map(int, input().split()))
five_cnt = 0
seven_cnt = 0

for a in A:
    if a == 5:
        five_cnt++
    if a == 7:
        seven_cnt++

if five_cnt == 2 and seven_cnt == 1:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

A = list(map(int, input().split()))
five_cnt = 0
seven_cnt = 0

for a in A:
    if a == 5:
        five_cnt += 1
    if a == 7:
        seven_cnt += 1

if five_cnt == 2 and seven_cnt == 1:
    print('YES')
else:
    print('NO')
x = 0
n = input(input())
for i in range(1,n+1):
    if i % 3 != 0 and i % 5 != 0:
        x += i
print(x)


### FIXED CODE ###

x = 0
n = int(input())
for i in range(1,n+1):
    if i % 3 != 0 and i % 5 != 0:
        x += i
print(x)
N = input()
A = list[map(int,input().split())]
count= 0
while(true):
    exist_odd = False
    for i in range(N):
        if(A[i]%2 != 0):
            exist_odd = True
    if(exist_odd == True):
        break
    for i in range(N):
        A[i] /= 2
    count += 1
print(count)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
count= 0
while(True):
    exist_odd = False
    for i in range(N):
        if(A[i]%2 != 0):
            exist_odd = True
    if(exist_odd == True):
        break
    for i in range(N):
        A[i] /= 2
    count += 1
print(count)
N = int(input())
divide = []
for i in range(2,int( (10**12) ** (1/ 2) ) + 1):
    while( N % i == 0):
        divide.append(i)
        N = int( N/i )
    if N ==1:
        break

i = 0
check = []
while(i < len(divide)-1):
    x = 1
    a = divide[:i+1]
    for j in a:
        x= x * j
    b = divide[i+1:]
    y = 1
    for j in b:
        y = y * j
    check.append(x + y)
    i += 1
    
ans = min(check) - 2
print(ans)


### FIXED CODE ###

N = int ( input() )
check_list = []
for i in range( 1, int( N**( 1/2 )+1 ) ):
    check = 0
    if N % i == 0:
        check = i + int( N / i ) - 2
        check_list.append(check)

print( min(check_list) )
a,b,k=map(int,input().split())
num=list(range(a,b+1))
ans=[]
if b-a+1<=k:
    for i in num:
        print(i)
    exit()
for i in range(k):
    ans.append(num[i])
    ans.append(num[-(i+1)])
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
ans=[]
for i in range(a,min(a+k,b+1),1):
    ans.append(i)
for i in range(b,max(a,b-k),-1):
    ans.append(i)
ans=list(set(ans)) #重複を削除
ans.sort() #ソート
for i in ans:
    print(i)
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
l = [''] * (L + 5)
cnt = 0
ok = True
for i in range (n):
    l [i * L / n] = s [i]
for i in range (m):
    ok &= (l [i * L / m] == '' or l [i * L / m] == t [i])
    l [i * L / m] = t [i]
if not ok: L = -1
print L


### FIXED CODE ###

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

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
d = defaultdict (str)
cnt = 0
ok = True
for i in range (n):
    d [i * L / n] = s [i]
for i in range (m):
    ok &= (d [i * L / m] == '' or d [i * L / m] == t [i])
    d [i * L / m] = t [i]
if not ok: L = -1
print L
def quick_sort(arr):
 left = []
 right = []
 if len(arr) <= 1:
  return arr
 ref = arr[0]
 ref_count = 0
 for ele in arr:
  if ele < ref:
   left.append(ele)
  elif ele > ref:
   right.append(ele)
  else:
   ref_count += 1
 left = quick_sort(left)
 right = quick_sort(right)
 return left + [ref] * ref_count + right

def binary_search1(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] >= target:
   if list[center-1] < target:
    result = center
    break
   else: right = center - 1
  elif list[center] < target:
   if center==N-1:
    result = N
    break
   else:
    left = center + 1
 if result == -1:
  return 0
 else:
  return str(result)

def binary_search2(list,target):
 result = -1
 left = 0
 right = len(list) - 1
 while left <= right:
  center = (left + right)//2
  if list[center] <= target:
   if list[center+1] > target:
    result = N-center-1
    break
   else:  left = center + 1
  elif list[center] > target:
   if center==0:
    result = N-center
    break
   else:
    right =center - 1
 if result == -1:
  return 0
 else:
  return str(result)

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A=quick_sort(A)
C=quick_sort(C)
K=0
for i in range(N):
 L=int(binary_search1(A,B[i]))
 M=int(binary_search2(C,B[i]))
 K+=L*M
print(K)

### FIXED CODE ###

import bisect
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
d=0
for i in B:
 d+=bisect.bisect_right(A,i-0.1)*(N-bisect.bisect_left(C,i+0.1))
print(d)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

offset = 0
while a[0] == b[offset]:
    offset += 1
c = []
for i in range(offset, offset + n):
    c.append(b[i % n])

for i in range(n):
    if a[i] == c[i]:
        print('No')
        exit()


print('Yes')
print(*c)


### FIXED CODE ###

import numpy as np
import sys 
read = sys.stdin.readline
n = int(input())
a = np.fromstring(read(), dtype=np.int32, sep=' ')
b = np.fromstring(read(), dtype=np.int32, sep=' ')[::-1]

kokan = []
same = -1
for i in range(n):
    if a[i] == b[i]:
        same = a[i]
if same == -1:
    print('Yes')
    print(*b)
    exit()

for i in range(n):
    if a[i] != b[i] and a[i] != same and b[i] != same:
        kokan.append(i)
for i in range(n):
    if a[i] == b[i]:
        if len(kokan) == 0:
            print('No')
            exit()
        else:
            j = kokan[-1]
            b[i], b[j] = b[j], b[i] 
            kokan.pop()
print('Yes')
print(*b)
n = int(input())
a = list(map(int,input().split()))
dics = {}
for i in range(len(n)):
    if a[i] in dics:
        dics[a[i]] = dics[a[i]]  + 1
    else:
        dics.update({a[i]:1})
    
#dics min max
dicsmin = min(list(dics.keys()))
dicsmax = max(list(dics.keys()))

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    #beam search x
    for j in range(len(a)):
        if a[j] == x or x-1 or x + 1:
            xcount = xcount + 1
    counter.append(xcount)
    
print(max(xcount))
        
    

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
roads = []
for i in range(m):
    roads += list(map(int, input().split()))
for road in roads:
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(1))

### FIXED CODE ###

n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
roads = []
for i in range(m):
    roads += [list(map(int, input().split()))]
for road in roads:
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(1))
N = int(input())
A = list(map(int, input().split()))

DP = [0] * (10 ** 6 + 1)

A.sort()
Sum = 0

for i in range(N):

    if DP[A[i]] == 0:
        for j in range(1, 10 ** 6):
            if A[i] * j <= 10 ** 6:
                DP[A[i] * j] = 1
            else:
                break

        if i == 0:
            if A[i] != A[i + 1]:
                Sum += 1
        elif i == N - 1:
            if A[i] != A[i - 1]:
                Sum += 1
        else:
            if A[i] != A[i + 1] and A[i] != A[i - 1]:
                Sum += 1

print(Sum)


### FIXED CODE ###

from collections import defaultdict

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

DP = [0] * (10 ** 6 + 1)

A.sort()
Sum = 0

d = defaultdict(int)
for key in A:
    d[key] += 1

for i in range(N):

    if DP[A[i]] == 0:
        for j in range(1, 10 ** 6):
            if A[i] * j <= 10 ** 6:
                DP[A[i] * j] = 1
            else:
                break

        if d[A[i]] == 1:
            Sum += 1
print(Sum)
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []*N

for i in range(N):
  num = lis[i]
  first[num] = i
  
for i in range(N):
  print(for _ in first)

### FIXED CODE ###


N = int(input())
lis = []
lis = list(map(int,input().split()))
first = [0]*N

for i in range(N):
    num = lis[i] - 1
    first[num] = i

for i in range(N):
    print(first[i]+1,end=' ')
print()
from math import pow

  
s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (pow(3,q)%mod+c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (pow(3,q)%mod + c*3) % mod
    q += 1
print(int(abc))

### FIXED CODE ###

s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (pow(3,q,mod) + c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (pow(3,q,mod) + c*3) % mod
    q += 1
print(int(abc))
num = input()
num_char = list(num)
if num_char[0] == "0":
	for i in range(0, int(len(num_char)),2):
		num_char[i] = 0
		num_char[i + 1] = 1
else:
	for i in range(0, int(len(num_char)),2):
		num_char[i] = 1
		num_char[i + 1] = 0
for i in num_char:
	print(i, end = "")

### FIXED CODE ###

s = input()
cnt1 = 0
cnt2 = 0
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "0":
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if s[i] == "1":
            cnt1 += 1
        else:
            cnt2 += 1
print(min(cnt1,cnt2))
lass Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()

### FIXED CODE ###

class Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()
n,k=map(int,input().split())
li=list(map(int,input().split()))
q=[]
for i in range(k,n):
  if li[i-1]<=0:
    q.append(-li[i-k])
  elif li[i-k]>=0:
    q.append(li[i-1])
  else:
    q.append(li[i-1]-li[i-k]+min(li[i-1],abs(li[i-k])))
print(min(q))

### FIXED CODE ###

n,k=map(int,input().split())
li=list(map(int,input().split()))
q=[]
if k==n:
  q.append(li[n-1]-li[0]+min(abs(li[n-1]),abs(li[0])))
else:
  for i in range(k,n+1):
    if li[i-1]<0:
      q.append(-li[i-k])
    elif li[i-k]>0:
      q.append(li[i-1])
    else:
      q.append(li[i-1]-li[i-k]+min(li[i-1],abs(li[i-k])))
print(min(q))
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(x,y,h)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
for i in range(101):
  for j in range(101):
    H = ph+abs(px-i)+abs(py-j)
    for l in ls:
      x, y, h = l
      u = max(H - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,H)
      flag = True
      break
  if flag:
    break
print(*ans)

### FIXED CODE ###

N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(x,y,h)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
flag = False
for i in range(101):
  for j in range(101):
    H = ph+abs(px-i)+abs(py-j)
    for l in ls:
      x, y, h = l
      u = max(H - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,H)
      flag = True
      break
  if flag:
    break
print(*ans)
a,b = map(int, input().split())
import math
print(mith.ceil((a + b) / 2)

### FIXED CODE ###

a,b = map(int, input().split())
import math
print(math.ceil((a + b) / 2))
a=input()
b=input()
aa=a[::-1]

if aa[1]==b[0] and aa[2]==b[1] and aa[3]==b[2]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a=input()
b=input()
aa=a[::-1]

if aa==b:
    print("YES")
else:
    print("NO")
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
X = [0] * (N+K+1000) # 後手必勝のところが1

X[K] = 1
for i in range(K)[::-1]:
    for a in A:
        if X[i+a] == 1:
            break
    else:
        X[i] = 1
        
print(["First", "Second"][X[0]])


### FIXED CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
X = [0] * (K + 1) # 後手必勝のところが1

X[K] = 1
for i in range(K)[::-1]:
    for a in A:
        if i + a <= K:
            if X[i+a] == 1:
                break
    else:
        X[i] = 1
        
print(["First", "Second"][X[0]])
w,h,n=map(int,input().split())

x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
      x1=max(x1,x)
  elif a==2:
      x2=min(x2,x)
  elif a==3:
      y1=max(y1,y)
  else:
      y2=min(y2,y)
        
s=(x2-x1)*(y4-y3)
if s<0:
  print(0)
else:
  print(s)

### FIXED CODE ###

w,h,n = map(int,input().split())
x1 = 0
x2 = w
y3 = 0
y4 = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        x1 = max(x1,x)
    elif a == 2:
        x2 = min(x2,x)
    elif a == 3:
        y3 = max(y3,y)
    else:
        y4 = min(y4,y)
X = x2 - x1
Y = y4 - y3
s = X * Y
if X < 0 or Y < 0:
    print(0)
else:
    print(s)
K,S=input().split("\n")
K=int(K)
S=str(S)
longS=len(S)
if longS <= K :
    print(S)
else:
    head=S[0]
    print(head + "...")

### FIXED CODE ###

K=input()
S=input()
K=int(K)
S=str(S)
longS=len(S)
if longS <= K :
    print(S)
else:
    head=S[0:K]
    print(head + "...")
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, m = na()
memo = [-1] * n
def dp(v):
    if memo[v] != -1:
        return memo[v]
    if G[v]:
        memo[v] = max(dp(i) for i in G[v]) + 1
    else:
        memo[v] = 0
    return memo[v]


G = [[] for _ in range(n)]
for _ in range(m):
    f, t = na()
    G[f-1].append(t-1)
print(max([dp(i) for i in range(n)]))

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, m = na()
memo = [-1] * n
def dp(v):
    if memo[v] != -1:
        return memo[v]
    if G[v]:
        memo[v] = max(dp(i) for i in G[v]) + 1
    else:
        memo[v] = 0
    return memo[v]


G = [[] for _ in range(n)]
for _ in range(m):
    f, t = na()
    G[f-1].append(t-1)
print(max([dp(i) for i in range(n)]))
# encoding:utf-8
input = list(map(int, input().split(" ")))
input.sort()
print (str(input_str[0]) + " " + str(input_str[1]) + " " + str(input_str[2]))

### FIXED CODE ###

# encoding:utf-8
input = list(map(int, input().split(" ")))
input.sort()
print (str(input[0]) + " " + str(input[1]) + " " + str(input[2]))
n = int(input())
if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
  print('hon')
elif n[-1]=='3':
  print('bon')
else:
  print('pon')

### FIXED CODE ###

n=input()
if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
  print('hon')
elif n[-1]=='3':
  print('bon')
else:
  print('pon')
a,=b=map(int,input().split())
print(a*(a-1)/2+b*(b-1)/2)

### FIXED CODE ###

a,b=map(int,input().split())
print (a*(a-1)//2+b*(b-1)//2)
import collections
from math import factorial

N = int(input())
S = [0]*N
for i in range(N):
    s = list(str(input()))
    s.sort()
    S[i] = "".join(s)

c = collections.Counter(S)
V = c.values()
V.sort()
cnt = 0
r = 2

for n in c.values():
    if n >= 2:
        cnt += factorial(n) / factorial(r) / factorial(n - r)
print(int(cnt))


### FIXED CODE ###

import collections
from math import factorial

N = int(input())
S = [0]*N
for i in range(N):
    s = list(str(input()))
    s.sort()
    S[i] = "".join(s)

c = collections.Counter(S)
cnt = 0
r = 2

for n in c.values():
    if n >= 2:
        a = factorial(n)
        b = factorial(r)*factorial(n - r)
        cnt += a/b
print(int(cnt))