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

N, M = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)
MM = 0
if M+1 >= N:
    MM = N
else:
    MM = M+1
Atop = [Asorted[N-i-1] for i in range(MM)]
for i in range(M):
    Atopmax = Atop.index(max(Atop))
    Atop[Atopmax] = Atop[Atopmax]//2
count = 0
for i in range(N-MM):
    count += Asorted[i]
count += sum(Atop)
print(count)

### FIXED CODE ###

#標準入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
#heapqをimportして、Aの要素をすべてマイナスにしてheapify
import heapq
def minus(n):
    return -n
A = list(map(minus, A))
heapq.heapify(A)
#その最小値を出力して削除し、その半分を追加することをM回やる
for i in range(M):
    heapq.heappush(A, -(-heapq.heappop(A)//2))
#Aの要素を合計してminusして出力する
print(minus(sum(A)))
### BUGGY CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,min(k,n)):
	dp[i]=abs(l[i]-l[0])
#print(dp)
for i in range(k,n):
  dp[i]=dp[i-1]+abs(l[i-1]-l[i])
  for j in range(k+1):
  	dp[i]=min(dp[i],dp[i-j]+abs(l[i-j]-l[i]))
#print(dp)
print(dp[n-1])
               

### FIXED CODE ###

import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,min(k,n)):
	dp[i]=abs(l[i]-l[0])
#print(dp)
for i in range(k,n):
  dp[i]=dp[i-1]+abs(l[i-1]-l[i])
  for j in range(k+1):
  	dp[i]=min(dp[i],dp[i-j]+abs(l[i-j]-l[i]))
#print(dp)
print(dp[n-1])
### BUGGY CODE ###

s = [s_i for s_i in input()]
i = ans = 0
while i < len(s) - 1:
    if s[i] == "B" and s[i+1] == "W":
        ans += 1
        s[i] = "W"
        s[i+1] = "B"
        i = 0
    else: i += 1
print(ans)

### FIXED CODE ###

s = [1 if x == "B" else 0 for x in input()]
ans = cnt = 0
for s_i in s:
    if s_i == 1: cnt += 1
    else: ans += cnt
print(ans)
### BUGGY CODE ###


import bisect


from functools import reduce
from operator import mul

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under




def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1
        ans_kari = cmb(data[i], data[left_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[left_ind]]
        ans_kari = cmb(data[i], data[right_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






if __name__ == '__main__':
    main()



### FIXED CODE ###


import bisect





def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1

        ans_kari_1 = min(data[left_ind], data[i] - data[left_ind])
        ans_kari_2 = min(data[right_ind], data[i] - data[right_ind])


        if ans_kari_1 > ans_kari_2:
            ans_list = [data[i], data[left_ind]]
        else:
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






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

from collections import* #defaultdict Counter deque appendleft
import sys
input=sys.stdin.readline

def main():
    n=int(input())
    d=[[]]+[deque(map(int,input().split()))for i in range(n)]

    c=0
    while any(d):
        c+=1
        f=0
        skip=set()
        for i in range(1,n+1):
            if i not in skip.copy():
                if d[i]:
                    if d[i][0] in skip:
                        continue
                    elif i==d[d[i][0]][0]:
                        oppo=d[i].popleft()
                        d[oppo].popleft()
                        skip.add(oppo)
                        skip.add(i)
                        f=1
                            
        if not f:
            print(-1)
            exit()

    print(c)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import* #defaultdict Counter deque appendleft
import sys
input=sys.stdin.readline
import time
t=time.time()

def main():
    n=int(input())
    d=[[]]+[deque(map(int,input().split()))for i in n*[0]]

    c=0
    while any(d):
        c+=1
        f=0
        skip=set()
        for i in range(1,n+1):
            if i not in skip:
                if d[i]:
                    if d[i][0] in skip:
                        continue
                    elif i==d[d[i][0]][0]:
                        oppo=d[i].popleft()
                        d[oppo].popleft()
                        skip.add(oppo)
                        skip.add(i)
                        f=1

        if not f:
            print(-1)
            exit()
        if abs(time.time()-t)>1:
            print(n*(n-1)//2)
            exit()

    print(c)

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

n, m = map(int, input().split())
abc = []
for i in range(m):
    a, b = map(int, input().split())
    c_ = list(map(int, input().split()))
    c = 0
    for v in c_:
        c += 2**(v-1)
    abc.append([a, b, c])

INF = 10**9
dp = [[INF for _ in range(1 << n)]for _ in range((m+1))]

for i in range(m):
    dp[i][0] = 0

for i in range(m):
    for j in range(1 << n):
        s = j | abc[i][2]
        dp[i+1][s] = min(dp[i+1][s], dp[i][j] + abc[i][0])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
if dp[-1][-1] == INF:
    print(-1)
else:
    print(dp[-1][-1])


### FIXED CODE ###

n, m = map(int, input().split())
abc = []
for i in range(m):
    a, b = map(int, input().split())
    c_ = list(map(int, input().split()))
    c = 0
    for v in c_:
        c += 2**(v-1)
    abc.append([a, b, c])

INF = 10**9
dp = [[INF for _ in range(1 << n)]for _ in range((m+1))]

for i in range(m):
    dp[i][0] = 0

for i in range(m):
    for j in range(1 << n):
        s = j | abc[i][2]
        dp[i+1][s] = min(dp[i+1][s], dp[i][j] + abc[i][0])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
if dp[-1][-1] == INF:
    print(-1)
else:
    print(dp[-1][-1])
### BUGGY CODE ###

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

sum=0
for i in range(n-1) :
  for j in range(n-i-1) :
    sum += a[i]*a[j+i+1]
    sum = sum%1000000007

print(sum)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
r_wa = [a[0]]
for i in range(n) :
  if i>0 :
    r_wa.append(r_wa[i-1]+a[i])

for i in range(n-1) :
  ans += a[i]*(r_wa[n-1]-r_wa[i])
  ans = ans%1000000007
print(ans)
### BUGGY CODE ###

#ABC-125-C
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

for i in range(N):
    check_gcd = -1
    for j in range(N):
#         print("i, j", i, j)
        if i == j:
            continue
        elif check_gcd == -1:
            check_gcd = A[j]
#             print("check_gcd", check_gcd)
        else:
            check_gcd = gcd(check_gcd, A[j])
#     print("i", i, "ans", ans_gcd, "check", check_gcd)
    ans_gcd = max(ans_gcd, check_gcd)
    
print(ans_gcd)

### FIXED CODE ###

#ABC-125-C
N = int(input())
A = list(map(int, input().split())) #[0, 1, 2, ..., N-2, N-1]
L = [0] * N #L[0]とL[N-1]は0から変わらない。N=5なら実行終了時にL=[*0*,a,b,c,*0*]となる。
R = [0] * N #R[0]とR[N-1]は0から変わらない。N=5なら実行終了時にR=[*0*,f,e,d,A[4]]となる。

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

#Lから埋める
L[0] = A[0]
check_gcd = L[0]
for i in range(1, N-1): #N=5のときはi=1~3を実施して最終的にL=[0,a,b,c,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    L[i] = check_gcd

#Rを埋める
R[-1] = A[-1]
check_gcd = R[-1]
for i in reversed(range(1, N-1)):#N=5のときはi=3~1を実施して最終的にR=[0,f,e,d,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    R[i] = check_gcd

#端以外を書き換えの対象とした場合の最大公約数のMaxを探す。
for i in range(1, N-1):
    m = gcd(L[i-1], R[i+1])
    ans_gcd = max(ans_gcd, m)

#端と比べて最終的な答えを出す。N>2のときは数字が低い方を消すだけ。
if N > 2:
    ans_gcd = max(ans_gcd, gcd(A[-2], L[N-3]), gcd(A[1], R[2]))
else:
    ans_gcd = max(A)

print(ans_gcd)
### BUGGY CODE ###

h, n = map(int,input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    ai ,bi = map(int,input().split())
    a[i] = ai
    b[i] = bi


mh = [0 for i in range(10003)]
for i in range(1,h+1):
    mb = 10**9
    for j in range(n):
        if mb > mh[i-a[j]] + b[j]:
            mb = mh[i-a[j]] + b[j]
    mh[i] = mb

print(mh[h])


### FIXED CODE ###

import numpy as np
h, n = map(int,input().split())
a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)
for i in range(n):
    ai ,bi = map(int,input().split())
    a[i] = ai
    b[i] = bi

mh = np.zeros(10001,dtype=int)
for i in range(1,h+1):
    mh[i] = (mh[i-a]+b).min()

print(mh[h])
### BUGGY CODE ###

n,q=map(int,input().split())
some=input()
lists=[]
    
for _ in range(q):
    add=list(map(int,input().split()))
    lists.append(add)
for j in range(q):
    nums=0
    nums+=some[lists[j][0]-1:lists[j][1]].count("AC")
    print(nums)


### FIXED CODE ###

n,q=map(int,input().split())
some=input()
lists=[]
for _ in range(q):
    add=list(map(int,input().split()))
    lists.append(add)

emptylists=[0]

for _ in range(n-1):
    numbers=emptylists[-1]
    if some[_ : _+2]=="AC":
        numbers=1+emptylists[-1]        
        emptylists.append(numbers)
    else:
        emptylists.append(numbers)

for j in range(q):
    print(emptylists[lists[j][1]-1]-emptylists[lists[j][0]-1])
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
count = []
for v in range(min(A), max(A) + 1):
    count.append(A.count(v - 1) + A.count(v) + A.count(v + 1))
print(max(count))

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)
### BUGGY CODE ###

a,b,n = (int(x) for x in input().split())
max=0
if n>=b:
    max=int(a*(b-1)/b)
    for x in range(b,n+1):
        y=int(a*x/b)-a*int(x/b)
        if y>max:
            max=y
else:
    for x in range(n+1):
        y=int(a*x/b)-a*int(x/b)
        if y>max:
            max=y

print(max)

### FIXED CODE ###

a,b,n = (int(x) for x in input().split())
x=min(b-1,n)
f=int(a*x/b)-a*int(x/b)
print(f)
### BUGGY CODE ###

s=input()+'E'
q=int(input())
for i in range(q):
  que=input().split()
  if que[0]==str(1):
    if s[-1]=='E':
      s='E'+s[:-1]
    else:
      s=s[1:]+'E'
  else:
    if que[1]==str(1):
      if s[-1]=='E':
        s=que[2]+s
      else:
        s='E'+s[1:]+que[2]
    else:
      if s[-1]=='E':
        s=s[:-1]+que[2]+'E'
      else:
        s='E'+que[2]+s[1:]
if s[-1]=='E':
  print(s[:-1])
else:
  print(s[::-1][:-1])



### FIXED CODE ###

from collections import deque
s=deque(input())
q=int(input())
cnt=0
for i in range(q):
  t=input().split()
  if t[0]=="1":
    cnt+=1
  else:
    if (int(t[1])+cnt)%2==1:
      s.appendleft(t[2])
    else:
      s.append(t[2])
      
if cnt%2==1:
  s.reverse()
print("".join(s))
### BUGGY CODE ###

I=input
N=int(I())
X=range(N)
S=[I()for _ in X]
print(sum(all(S[(i+k)%N][j]==S[(j+k)%N][i]for i in X for j in X)for k in X)*N)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = [list(input().rstrip()) for _ in range(N)]
row = [[0] * 26 for _ in range(N)]
col = [[0] * 26 for _ in range(N)]
for i in range(N):
    for j in range(N):
        c = ord(S[i][j]) - ord('a')
        row[i][c] += 1
        col[j][c] += 1
ans = 0
same = [[row[i] == col[j] for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if all(same[(i+k) % N][(j+k) % N] for k in range(N)):
            ans += 1
print(ans)
### BUGGY CODE ###

def reflesh_string(current_answer):
    index = min(K, len(current_answer))
    return current_answer[:index]

def update_string(string_answer):
    string_answer = string_answer.replace("1", "1")
    string_answer = string_answer.replace("2", "22")
    string_answer = string_answer.replace("3", "333")
    string_answer = string_answer.replace("4", "4444")
    string_answer = string_answer.replace("5", "55555")
    string_answer = string_answer.replace("6", "666666")
    string_answer = string_answer.replace("7", "7777777")
    string_answer = string_answer.replace("8", "88888888")
    string_answer = string_answer.replace("9", "999999999")
    return string_answer
  
def check_skip(current_answer):
    counter = [0 for i in range(10)]
    for k in range(min(K, len(current_answer))):
        counter[int(current_answer[k])] = 1
    if(sum(counter) == 1):
        return True
    
    if(sum(counter) == 2 and current_answer[min(K, len(current_answer)) - 1] != "1"):
        return True
    
    return False
    
S = input().strip()
K = int(input().strip())
for c in range(5 * 10**15):
    S = update_string(S)
    S = reflesh_string(S)
    if(check_skip(S)):
        break
print(S[min(K, len(S)) - 1])

### FIXED CODE ###

S = input().strip()
K = int(input().strip())

ans = 1
for i in range(min(K, len(S))):
    if(S[i] != "1"):
        ans = S[i]
        break
        
print(ans)
### BUGGY CODE ###

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

m = [[0]*n for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  m[a][b] = 1
  m[b][a] = 1
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in range(n):
    if m[c][i] == 1 and dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

#[exit(print('No')) for i in range(1,n)  if dp[i] == 0]

print('Yes')
[print(dp[i]) for i in range(1,n)]


### FIXED CODE ###

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

m = [[] for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  m[a].append(b)
  m[b].append(a)
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in m[c]:
    if dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

#[exit(print('No')) for i in range(1,n)  if dp[i] == 0]

print('Yes')
[print(dp[i]) for i in range(1,n)]
### BUGGY CODE ###

import pprint
H, W, M = map(int, input().split())
bombs = [[0 for _ in range(W)] for _ in range(H)]
hCount = [0]*H
vCount = [0]*W

for i in range(M):
    h, w = map(int, input().split())
    h -= 1; w -= 1;
    hCount[h] += 1
    vCount[w] += 1
    bombs[h][w] = 1

hMax = max(hCount)
vMax = max(vCount)
hMaxIndex = [i for i, x in enumerate(hCount) if x==max(hCount)]
vMaxIndex = [i for i, x in enumerate(vCount) if x==max(vCount)]

ans = -1
for y in hMaxIndex:
    for x in vMaxIndex:
        if bombs[y][x]:
            ans = max(hMax + vMax - 1, ans)
        else:
            ans = max(hMax+vMax, ans)
print(ans)


### FIXED CODE ###

import pprint
H, W, M = map(int, input().split())
bombs = set()
hCount = [0]*H
vCount = [0]*W

for i in range(M):
    h, w = map(int, input().split())
    h -= 1; w -= 1;
    hCount[h] += 1
    vCount[w] += 1
    bombs.add((h, w))

hMax = max(hCount)
vMax = max(vCount)
hMaxIndex = [i for i, x in enumerate(hCount) if x==hMax]
vMaxIndex = [i for i, x in enumerate(vCount) if x==vMax]

ans = -1
for x in vMaxIndex:
    for y in hMaxIndex:
        if (y, x) in bombs:
            continue
        else:
            print(hMax + vMax)
            exit()
print(hMax + vMax - 1)
### BUGGY CODE ###

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

def cal(a, b):
    c = [1]
    for i in range(2, min(a, b)+1):
        if a%i == 0 and b%i == 0:
            if len(c) == 1:
                c.append(i)
            else:
                for j, k in enumerate(c[1:]):
                    if i%k == 0:
                        break
                    elif j == len(c)-2:
                        c.append(i)
    return c

ans = cal(a, b)
print(len(ans))


### FIXED CODE ###

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def cal(c):
    d = []
    while c%2 == 0:
        d.append(2)
        c //= 2
    f = 3
    while f**2 <= c:
        if c%f == 0:
            d.append(f)
            c //= f
        else:
            f += 2
    if c != 1:
        d.append(c)
    return d
    
c = gcd(a, b)
d = cal(c)
print(len(set(d))+1)
### BUGGY CODE ###

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

if A[0] != 0:
    B = A + [K] 
else:
    B = A
#print(B)

for i in range(N):
    B.append(A[i] + K)
#print(B)

ans = 10000000
C =[]
for i in range(N):
    cnt = 0
    for j in range(i, i + N - 1):
        cnt +=B[j+1] - B[j]
    ans = min(ans,cnt)

print(ans)

### FIXED CODE ###

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

a = K + A[0]
A = A + [a]

#print(A)

B = []
for i in range(N):
    B.append(A[i+1] - A[i])
B = sorted(B,reverse = False)

print(sum(B) - max(B))
### BUGGY CODE ###

def comb(n,k):
    nCk = 1
    MOD = 10**9+7
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = -1
nck = 0

for i in range(n):
    tmp = comb(ai, a[i])
    if nck <= tmp:
        nck = tmp
        aj = a[i]

print(str(ai) + " " + str(aj))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))
### BUGGY CODE ###

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

even=0
div=0
A=[]
for i in range(n):
    if a[i] not in A:
        div += 1
        A.append(a[i])
        if a.count(a[i])%2 == 0:
            even += 1
if even%2 == 0:
    print(div)
else:
    print(div-1)

### FIXED CODE ###

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

import collections
c=collections.Counter(a)
C=c.most_common()

even=0
for i in range(len(C)):
    p,q=C[i]
    if q%2==0:
        even += 1
if even%2==0:
    print(len(C))
else:
    print(len(C)-1)
### BUGGY CODE ###

n = int(input())

array = [[int(x) for x in input().split()] for x in range(n)]

taka = array[0][0]
ao = array[0][1]

for item in array[1:]:
    taka_tmp = item[0]
    ao_tmp = item[1]

    cnt = 1
    while True:
        if taka_tmp*cnt >= taka and ao_tmp*cnt >= ao:
            taka = taka_tmp*cnt
            ao = ao_tmp*cnt
            break
        cnt += 1
print(ao+taka)

### FIXED CODE ###

from decimal import Decimal, ROUND_CEILING

n = int(input())
ta_array = [[int(x) for x in input().split()] for y in range(n)]
res = 1
prev_t, prev_a = ta_array.pop(0)
for t, a in ta_array:
    res_a = Decimal(prev_a*res/a).quantize(Decimal(0.0), rounding=ROUND_CEILING)
    res_t = Decimal(prev_t*res/t).quantize(Decimal(0.0), rounding=ROUND_CEILING)
    res = max(res_a, res_t)
    prev_t = t
    prev_a = a
print(prev_t*res+prev_a*res)
### BUGGY CODE ###

def f1(x):
    A = []
    if x == 0:
        return 0
    while x > 0:
        A.append(str(x % 2))
        x //= 2
    A.reverse()
    return ''.join(A)

def f2(x, a):
    bx = int(f1(x))
    ba = int(f1(a))
    xor = str(bx + ba).replace('2', '0')
    ans = 0
    for i in range(len(xor) - 1, -1, -1):
        ans += int(xor[::-1][i]) * 2 ** i
    return ans

n, k = map(int, input().split())
A = [int(i) for i in input().split()]

ans = 0
for i in range(k + 1):
    tmp = 0
    for j in range(n):
        tmp += f2(i, A[j])
    ans = max(ans, tmp)
    
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
Ai = list(map(int, input().split()))
 
D = 40
Bi = []
for a in Ai:
    b = bin(a)[2:]
    b = ("0" * (D - len(b))) + b
    Bi.append(b)
 
result = ""
for i in range(D):
    count = 0 # 1の個数
    for i, b in enumerate(Bi):
        if b[0] == '1':
            count += 1
        Bi[i] = b[1:]
    if count >= N / 2:
        result += "0"
    else:
        result += "1"
    #count = count // 2
x = 0
for i in range(D):
    if result[0] == '1':
        a = pow(2, D - i - 1)
        if x + a <= K:
            x += a
    result = result[1:]
 
ans = 0
for a in Ai:
    ans += (a ^ x)
print(ans)
### BUGGY CODE ###

n=int(input())

ans_list = []
for i in range(n):
    ans=0
    N = i+1
    for x in range(1,int(n**0.5)+1):
        for y in range(1,int((n-x**2)**0.5)+1):
            for z in range(1,int((n-x**2-y**2)**0.5)+1):
                if x**2+y**2+z**2+x*y+y*z+z*x==N:
                    ans+=1
    ans_list.append(ans)

for i in range(n):
    print(ans_list[i])

### FIXED CODE ###

n=int(input())

ans = [0]*n
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            if x**2+y**2+z**2+x*y+y*z+z*x <= n:
                ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

def main():
	s = int(input())
	import math
	from functools import reduce
	import itertools
	def gcd_list(numbers):
		return reduce(math.gcd, numbers)

	ans = 0
	l = list(itertools.product(list(range(1,s+1)),repeat = 3))

	for i in range(len(l)):
		ans += gcd_list(l[i])
	print(ans)

if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	s = int(input())
	import math
	from functools import reduce
	import itertools
	def gcd(*numbers):
		return reduce(math.gcd, numbers)

	ans = 0
	for a in range(1,s+1):
		for b in range(1,s+1):
			for c in range(1,s+1):
				m = gcd(a,b,c)
				ans += m
	print(ans)

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

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

dp=[-1]*100100
G=[[] for _ in range(100100)]

def dfs(v):
  if dp[v]!=-1:
    return dp[v]

  x=0
  for w in G[v]:
    r=dfs(w)+1
    x=max(x,r)

  return x

def main():
  n,k=LI()
  for _ in range(k):
    a,b=LI()
    a-=1
    b-=1
    G[a].append(b)

  ans=0
  for i in range(n):
    ans=max(ans,dfs(i))

  return ans

print(main())
# main()


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

dp=[-1]*100100
G=[[] for _ in range(100100)]

def dfs(v):
  if dp[v]!=-1:
    return dp[v]
  dp[v]=r=max(dfs(w) for w in G[v])+ 1 if G[v] else 0
  return r

def main():
  n,k=LI()

  for _ in range(k):
    a,b=LI()
    a-=1
    b-=1
    G[a].append(b)

  return max(dfs(v) for v in range(n))

# main()
print(main())