Harryxun/stf_run huggingface dataset:
def is_palindrome(s):
    i = 0
    n = len(s)-1
    while s[i] == s[n]:
        i += 1
        n -= 1
        if i >= n:
            break
    else:
        return False
    return True

s = input()
n = len(s)

if is_palindrome(s) and is_palindrome(s[0:(n-1)//2-1]) and is_palindrome(s[(n+3)//2-1:]):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

def is_palindrome(s):
    if len(s) > 1:
        i = 0
        n = len(s)-1
        while s[i] == s[n]:
            i += 1
            n -= 1
            if i >= n:
                break
        else:
            return False
        return True
    else:
        return True

s = input()
n = len(s)

if is_palindrome(s) and is_palindrome(s[0:(n-1)//2]) and is_palindrome(s[(n+3)//2-1:]):
    print("Yes")
else:
    print("No")
A,B=map(int,input().split())
import math
print(int((A*B)/math.gcd(A,B)))

### FIXED CODE ###

A,B=map(int,input().split())
import fractions
print(int((A*B)/fractions.gcd(A,B)))
n = int(input())
ai = [int(x) for x in input().split()]

ai.sort()

temp = [abs(x) for x in ai[1:-1]]

o1 = -ai[0] + sum(temp) + ai[-1]

print(o1)

temp1 = ai.pop(-1)
num_p = sum(x >= 0 for x in ai)
if num_p is len(ai):
  num_p = len(ai) - 1
for i in range(num_p):
  temp2 = ai.pop(-1)
  print(ai[0], temp2)
  ai[0] -= temp2

for i in range(len(ai)):
  temp2 = ai.pop(0)
  print(temp1, temp2)
  temp1 -= temp2

### FIXED CODE ###

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

ai.sort()

temp = [abs(x) for x in ai[1:-1]]

o1 = -ai[0] + sum(temp) + ai[-1]

print(o1)

temp1 = ai.pop(-1)
num_p = sum(x >= 0 for x in ai)
if num_p == len(ai):
  num_p -= 1
for i in range(num_p):
  temp2 = ai.pop(-1)
  print(ai[0], temp2)
  ai[0] -= temp2

for i in range(len(ai)):
  temp2 = ai.pop(0)
  print(temp1, temp2)
  temp1 -= temp2
buttons = {"A","B"}
buttons["A","B"]=(A,B)

def game():
  num = 0
  value = 0
  while num < 2:
    if buttons["A"] >= button["B"]:
      value += buttons["A"]
      buttons["A"] -= 1
    else:
      value += buttons["B"]
      buttons["B"] -= 1
    num += 1
  return(value)
print(game())

### FIXED CODE ###

 # A - Buttons
a, b = list(map(int, input().split()))
first = max(a, b)
if a == first:
	a -= 1
else:
 	b -= 1
second = max(a, b)
print(first + second)
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  if ans.count(0) == m:
    print(-1)
  else:
    for i in range(len(ans)):
      answ += ans[i]*(10**(m-1-i))
    
    print(answ)

### FIXED CODE ###

n,m = list(map(int, input().split()))
x = []
ans = [0]*n
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)

if (n == 1) and (m == 0):
  print(0)
elif m == 0:
  ans[0] = 1
  for i in range(len(ans)):
    answ += ans[i]*(10**(n-1-i))
    
  print(answ)
elif has_duplicates(s):
  print(-1)
elif (n == 1) and (c.count(0) == 1):
  print(0)
else:
  for i,j in x:
    ans[i-1] = j
    
  if (ans[0] == 0) and (s.count(1) == 0):
    ans[0] = 1
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(n-1-i))

  if ans[0] == 0:
    print(-1)
  else:
    print(answ)
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    arr = []
    for _ in range(n):
        temp = nl()
        arr.append(temp)

    costs = []
    for i in range(2**n):
        binary = bin(i)[2:]
        binary = '0'*(m-len(binary)) + binary
        count = [0]*m
        cost = 0
        for i, num in enumerate(binary):
            if num == '1':
                for j in range(m):
                    count[j] += arr[i][j+1]
                cost += arr[i][0]
        #print(binary, cost)
        flag = True
        for value in count:
            if value < x:
                flag = False
        if flag:
            costs.append(cost)
    try:
        print(min(costs))
    except ValueError:
        print(-1)
    

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    arr = []
    for _ in range(n):
        temp = nl()
        arr.append(temp)

    costs = []
    for i in range(2**n):
        binary = bin(i)[2:]
        binary = '0'*(n-len(binary)) + binary
        count = [0]*m
        cost = 0
        for i, num in enumerate(binary):
            if num == '1':
                for j in range(m):
                    count[j] += arr[i][j+1]
                cost += arr[i][0]
        #print(binary, cost)
        flag = True
        for value in count:
            if value < x:
                flag = False
        if flag:
            costs.append(cost)
    if costs == []:
        print(-1)
    else:
        print(min(costs))
    

if __name__ == '__main__':
    main()
a,b = map(int, input().Split())
print(a+b if a+b<10 else "error") 

### FIXED CODE ###

a,b = map(int, input().split())
print(a+b if a+b<10 else "error")
a,b=map('raw_input()','raw_input())
c=a*b
d=2*a+2*b
print'c d'

### FIXED CODE ###

a,b = map(int, raw_input().split())
c = a*b
d = 2*(a+b)
print'%d %d'%(c,d)
n = input()
p=input()
p=p[0:-1]
if n==p:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n, k = map(int, input().split())
if n<=k:
  print("unsafe")
else:
  print("safe")
N=int(input())
import math

for i in range(1,N+1):
    ans=0
    for x in range(1,33):
        x2=x*x
        for y in range(1,x+1):
                    a=-(3*(x2)+3*(y*y)+2*x*y)/4+i
                    if a>0:
                        b=(math.sqrt(a)-(x+y)/2)
                        if b>0 and b%1==0.0:
                            if x==y:
                                ans+=1
                            else:
                                ans+=2

    print(ans)



### FIXED CODE ###

L,R,D=map(int,input().split())
ans=0
for i in range(L,R+1):
    if i%D==0:
        ans+=1
    else:
        pass

print(ans)
n=int(input())
s=[list(map(str,input().split())) for _ in range(n)]
t=list(set(s))
print(len(t))


### FIXED CODE ###

n=int(input())
s=[input() for _ in range(n)]
t=list(set(s))
print(len(t))
n,k=map(int,input().split())
li=[[0,0] for i in range(n)]
for i in range(n):
    li[i][0],li[i][1]=map(int,input().split())

li.sort(reverse=True,key=lambda x:x[1])

def find_num_neta(choice,li):
    k=[]
    for i in choice:
        k.append(li[i][0])
    return len(set(k))

#-----------------------------------------
best_list=[]
best_list_neta=[]
not_best_list=[]

for i in li:
    if i[0] in best_list_neta:
        not_best_list.append(i[1])
    else:
        best_list.append(i[1])
        best_list_neta.append(i[0])


s2=min(len(best_list_neta),k)
s1=find_num_neta(list(range(k)),li)


score=-1
oishisa=[0 for i in range(n)]
oishisa[s1]=sum([li[p][1] for p in range(k)])

for i in range(s1+1,s2+1):
    oishisa[i]=oishisa[i-1]-not_best_list[k-i]+best_list[i-1]
    
    new_score=i**2+oishisa[i]

    if score<new_score:
        score=new_score
        
    
print(score)

### FIXED CODE ###

n,k=map(int,input().split())
li=[[0,0] for i in range(n)]
for i in range(n):
    li[i][0],li[i][1]=map(int,input().split())



def find_num_neta(choice,li):
    k=[]
    for i in choice:
        k.append(li[i][0])
    return len(set(k))
#-----------------------------------------

li.sort(reverse=True,key=lambda x:x[1])
s2=min(find_num_neta(list(range(n)),li),k)
s1=find_num_neta(list(range(k)),li)
oishisa=sum([li[i][1] for i in range(k)])
score=oishisa+s1**2

#-----------------------------------------
li.sort(key=lambda x:x[0])
best_list=[]
not_best_list=[]


m=-1
for i in li:
    if m==i[0]:
        not_best_list.append(i)
    else:
        best_list.append(i)
        m=i[0]
        
not_best_list.sort(reverse=True,key=lambda x:x[1])
best_list.sort(reverse=True,key=lambda x:x[1])



 
 
for i in range(s1+1,s2+1):
    oishisa=oishisa+best_list[i-1][1]-not_best_list[k-i][1]
    
    new_score=i**2+oishisa
    
    if score<new_score:
        score=new_score
        
    
print(score)
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    ans = 0
    if X > N//2:
        X = N-X

    ans = X

    def f(n, x):
        ans = 0
        ans += n
        n_x = n // x
        ans += 2*n_x*x - x
        if n_x % x != 0:
            ans += f(x, n - n_x*x)

        # print(n, x, n_x, 2*n_x*x - x, ans)
        return ans

    return ans + f(N-X, X)


def main():
    N, X = read_int_n()
    print(slv(N, X))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    if N % 2 == 0 and X == N//2:
        return 3*X
    ans = 0
    if X > N//2:
        X = N-X

    ans = X

    def f(n, x):
        # print(n, x)
        ans = 0
        ans += n
        n_x = n // x
        ans += 2*n_x*x - x
        if n % x != 0:
            ans += f(x, n - n_x*x)

        # print(n, x, n_x, 2*n_x*x - x, ans)
        return ans

    return ans + f(N-X, X)


def main():
    N, X = read_int_n()
    print(slv(N, X))

  

if __name__ == '__main__':
    main()
x, y = map(int, input().split())

if x >= 0 and y >= 0:
    if x =< y:
        print(y - x)
    else:
        if y == 0:
            print(1 + x - y)
        else:
            print(x - y + 2)
elif x < 0 and y < 0:
    if y >= x:
        print(y - x)
    else:
        print(2 + x - y)
else:
    if y == 0:
        print(abs(abs(x) - abs(y)) + 1)
    else:
        print(abs(abs(x) - abs(y)) + 2)

### FIXED CODE ###

x, y = map(int, input().split())

if x >= 0 and y >= 0:
    if y >= x:
        print(y - x)
    else:
        if y == 0:
            print(1 + x - y)
        else:
            print(x - y + 2)
elif x < 0 and y < 0:
    if y >= x:
        print(y - x)
    else:
        print(2 + x - y)
else:
    if y == 0:
        print(abs(abs(x) - abs(y)))
    else:
        print(abs(abs(x) - abs(y)) + 1)
from sys import stdin
import operator
readline = stdin.readline


def norm(self):
    return abs(self)


def closest_pair(p):
    m = 0
    p.sort(key=operator.attrgetter('real'))
    d = float('inf')
    for i in range(1, len(p)):
        for j in reversed(range(m, i)):
            tmp = p[i] - p[j]
            if d < tmp.real:
                m = j + 1
                break
            tmp = abs(tmp)
            if d > tmp:
                d = tmp
    return d


from itertools import combinations


def brute_force(p):
    return min(abs(p[i] - p[j]) for i, j in combinations(range(len(p)), 2))


@profile
def main():
    n = int(readline())
    p = [map(float, readline().split()) for _ in range(n)]
    p = [x + y * 1j for x, y in p]

    # print('{:.6f}'.format(brute_force(p)))
    print('{:.6f}'.format(closest_pair(p)))
main()

### FIXED CODE ###

from sys import stdin
from operator import attrgetter
readline = stdin.readline


def norm(a):
    return a.real * a.real + a.imag * a.imag


def closest_pair(p):
    if len(p) <= 1:
        return float('inf')
    m = len(p) // 2
    d = min(closest_pair(p[:m]), closest_pair(p[m:]))
    p = [pi for pi in p if p[m].imag - d < pi.imag < p[m].imag + d]
    return brute_force(p, d)

def brute_force(p, d=float('inf')):
    p.sort(key=attrgetter('real'))
    for i in range(1, len(p)):
        for j in reversed(range(i)):
            tmp = p[i] - p[j]
            if d < tmp.real:
                break
            tmp = abs(tmp)
            if d > tmp:
                d = tmp
    return d


def main():
    n = int(readline())
    p = [map(float, readline().split()) for _ in range(n)]
    p = [x + y * 1j for x, y in p]

    p.sort(key=attrgetter('imag'))
    print('{:.6f}'.format(closest_pair(p)))
main()
import numpy as np
import sys
sys.setrecursionlimit(10**8)

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

a2 = []
for i in range(n):
    a2.append((a[i], i))
a2.sort(reverse=True)

dp = np.full((n, n, n), -1)


def solve(i2, s, e):
    if dp[i2][s][e] != -1:
        return dp[i2][s][e]

    a, i = a2[i2]

    if i2 == n-1:
        dp[i2][s][e] = a * abs(s-i)
        return dp[i2][s][e]

    dp[i2][s][e] = max(solve(i2+1, s+1, e) + a * abs(s - i),
                       solve(i2+1, s, e-1) + a * abs(e - i))

    return dp[i2][s][e]


print(solve(0, 0, n-1))


### FIXED CODE ###

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

a2 = []
for i in range(n):
    a2.append((a[i], i))
a2.sort(reverse=True)

dp = [[-1] * n for _ in range(n)]
for i2 in range(n-1, -1, -1):
    a, i = a2[i2]

    for s in range(i2+1):
        if i2 == n-1:
            dp[i2][s] = a * abs(s-i)
        else:
            dp[i2][s] = max(dp[i2+1][s+1] + a * abs(s - i),
                            dp[i2+1][s] + a * abs(n-1-i2+s - i))

print(dp[0][0])
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x = max(x)
y = min(y)

flag = True
for z in range(-100, 100+1):
    if x < z <= y and X < Z <= Y:
        flag = False
        
if flag:
    print('War')
else:
    print('No War')

### FIXED CODE ###

n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x = max(x)
y = min(y)

flag = True
for z in range(-100, 100+1):
    if x < z <= y and X < z <= Y:
        flag = False
        
if flag:
    print('War')
else:
    print('No War')
n = input()

a = ['+','-']

b = ''
ans = ''
for i in a:
    b += n[0]+i
    for j in a:
        b += n[1]+j
        for k in a:
            b += n[2]+k+n[3]
            if eval(b) == 7:
                ans = b+'=7'
            else:
                b = ''
print(ans)

### FIXED CODE ###

n = input()

a = ['+','-']
b = ''
for i in a:
    for j in a:
        for k in a:
            if eval(n[0]+i+n[1]+j+n[2]+k+n[3]) == 7:
                b =n[0]+i+n[1]+j+n[2]+k+n[3]+'=7'
                break
print(b)
l,r = map(int,raw_input().split())

now = [0]*2020

for a in range(l,r+1):
  now[a % 2019] = 1
  if now[0] == 1 or (now[3]==1 and now[673]==1):
    print 0
    exit(0)

ans = 2019*2019
for x in range(2019):
  if now[x] == 1:
    for y in range(2019):
      if now[y] == 1 and x != y:
        buf = (x*y)%2019
        if ans > buf:
          ans = buf
print ans


### FIXED CODE ###

l,r = map(int,raw_input().split())

now = [0]*2020

a = l
while a < r+1:
  now[a % 2019] = 1
  a += 1
  if now[0] == 1 or (now[3]==1 and now[673]==1):
    print 0
    exit(0)

ans = 2019*2019
for x in range(2019):
  if now[x] == 1:
    for y in range(2019):
      if now[y] == 1 and x != y:
        buf = (x*y)%2019
        if ans > buf:
          ans = buf
print ans
lis = "abcdefghijklmnopqrstuvwxyz"

z = input()

for a in range(len(lis)-1):
  if z = lis[a]:
    print(lis[a+1])
    exit()

### FIXED CODE ###

lis = "abcdefghijklmnopqrstuvwxyz"
 
z = input()
 
for a in range(len(lis)-1):
  if z == lis[a]:
    print(lis[a+1])
    exit()
count =1

while True:
    a,b =int(input())

    if a !=0 and b != 0 and a < b:
        a,b = a,b

    if a !=0 and b != 0 and b < a:
        a, b =b,a

    else:
         break

### FIXED CODE ###

while True:
    x,y  =[int(i) for i in input().split()]

    if x == y == 0:
       break

    if x > y:
        x,y = y,x

    print(x,y)
N=int(input())
X= list(map(int,input().split()))
cnt = 1000000
for j in range(100):
    t = 0
    for i in li:
        t += (i-(j+1))**2
    if t <= cnt:
        cnt = t
print(cnt)


### FIXED CODE ###

N=int(input())
X= list(map(int,input().split()))
cnt = 1000000
for j in range(100):
    t = 0
    for i in X:
        t += (i-(j+1))**2
    if t <= cnt:
        cnt = t
print(cnt)
N = int(input())
l = []
for i in range(1, N-1):
  if type(N/i) == int:
    l.append(i + N/i)
print(min(l)-2)
    

### FIXED CODE ###

N = float(input())
l = []
for i in range(1,1000001):
  a = N/i
  if a.is_integer():
    l.append(i + N/i)
print(int(min(l)-2))
weather=input()
weathers={"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy": "Sunny"}
print(weathers[wearther])

### FIXED CODE ###

weather=input()
weathers={"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy": "Sunny"}
print(weathers[weather])
class UnionFind():
    def __init__(self,n):
        self.n = n
        
        # parents が負の時は要素数
        # parents が正の時は親の番号
        self.parents = [-1] * n
 
    # xの根を求める
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            # 根を再帰的に求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    # xとyを併合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
 
        # 根が同じ場合はreturn
        if x == y:
            return
 
        # ランクを考慮（要素数の少ない木を要素数の多い木に併合）
        if self.parents[x] > self.parents[y]:
            x,y = y,x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    # xの木の要素数を求める
    def size(self,x):
        return - self.parents[self.find(x)]
 
    # xとyが同じ木なのか確かめる
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
 
n, m, k = (int(x) for x in input().split())

uf = UnionFind(n)
n_find = [0] * n

for i in range(n):
    a, b = (int(x) for x in input().split())

    a -= 1
    b -= 1

    n_find[a] += 1
    n_find[b] += 1
    uf.union(a, b)

ans = [uf.size(i) -1 - n_find[i] for i in range(n)] 

for i in range(k):
    c, d = (int(x) for x in input().split())

    c -= 1
    d -= 1

    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)

    

### FIXED CODE ###

class UnionFind():
    def __init__(self,n):
        self.n = n
        
        # parents が負の時は要素数
        # parents が正の時は親の番号
        self.parents = [-1] * n
 
    # xの根を求める
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            # 根を再帰的に求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    # xとyを併合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
 
        # 根が同じ場合はreturn
        if x == y:
            return
 
        # ランクを考慮（要素数の少ない木を要素数の多い木に併合）
        if self.parents[x] > self.parents[y]:
            x,y = y,x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    # xの木の要素数を求める
    def size(self,x):
        return - self.parents[self.find(x)]
 
    # xとyが同じ木なのか確かめる
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
 
n, m, k = (int(x) for x in input().split())

uf = UnionFind(n)
n_find = [0] * n

for i in range(m):
    a, b = (int(x) for x in input().split())

    a -= 1
    b -= 1

    n_find[a] += 1
    n_find[b] += 1
    uf.union(a, b)

ans = [uf.size(i) -1 - n_find[i] for i in range(n)] 

for i in range(k):
    c, d = (int(x) for x in input().split())

    c -= 1
    d -= 1

    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)
import sys
import math

n = int(raw_input())

root = math.floor(math.sqrt(n))
print(int(root * root))

### FIXED CODE ###

import sys
import math

n = int(input())

root = math.floor(math.sqrt(n))
print(int(root * root))
import collections

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.collections.popleft()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)


### FIXED CODE ###

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)
import math
(a,b,c,d)=map(int,input().split())
g=int(c*d/math.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)
print(b-a+1-k)



### FIXED CODE ###

import math
import fractions
(a,b,c,d)=map(int,input().split())
g=c*d//fractions.gcd(c,d)
k=0
k+=b//c+b//d-b//g-int(a-1)//c-(a-1)//d+(a-1)//g

print(b-a+1-k)
n,k=map(int,input().split())
ans = [i for i in range(1,n+1)]
for i in range(k):
	a=list(map(int,input().split()))
	for j in a:
      if j in ans:
        ans.remove(j)
print(len(ans))

### FIXED CODE ###

n,k=map(int,input().split())
ans = [i for i in range(1,n+1)]
for i in range(k):
  input()
  a=list(map(int,input().split()))
  for j in a:
    if j in ans:
      ans.remove(j)
print(len(ans))