Harryxun/stf_run huggingface dataset:
from collections import defaultdict
def main():
    n, k = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))
    s = []
    ord = [-1]*(n)
    u = 1
    while ord[u] == -1:
        ord[u] = len(s)
        s.append(u)
        u = a[u-1]
    l = len(s) - ord[u]
    if k < ord[u]:
        print(s[k])
    else:
        print(s[(k-ord[u])%l+ord[u]])

'''
def main():
    n, k = map(int, input().split(" "))
    a = list(map(lambda i: int(i)-1, input().split(" ")))
    s = [0]
    d = defaultdict(lambda:0)
    x = a[0]
    for i in range(n):
        s.append(x)
        x = a[x]

    bb=None
    for i in range(n):
        d[s[i]] += 1
        if d[s[i]] ==2:
            bb=s[i]
            break

    cc = s.index(bb)
    s[cc]=-1
    dd = s.index(bb)
    loop_len = dd-cc
    s[cc]=s[dd]
        
    if bb ==None or k < cc:
        print(s[k]+1)
    else:
        y = (k-cc) % loop_len
        print(s[y+cc]+1)
'''
if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import defaultdict
def main():
    n, k = map(int, input().split(" "))
    a = list(map(lambda i: int(i)-1, input().split(" ")))
    s = [0]
    d = defaultdict(lambda:0)
    x = a[0]
    for i in range(n):
        s.append(x)
        x = a[x]

    bb=None
    for i in range(n):
        d[s[i]] += 1
        if d[s[i]] ==2:
            bb=s[i]
            break

    cc = s.index(bb)
    s[cc]=-1
    dd = s.index(bb)
    loop_len = dd-cc
    s[cc]=s[dd]
        
    if bb ==None or k < cc:
        print(s[k]+1)
    else:
        y = (k-cc) % loop_len
        print(s[y+cc]+1)

if __name__ == "__main__":
    main()
import sys
import math
import numpy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
 
s = int(readline())
if s % 2 == 1:
    print(0)
else:
    s //= 2
    ans = 0
    while s:
        s //= 5
        ans += s
    print(ans)

### FIXED CODE ###

def is_poor(triple_numbers):
    count_map = {}
    for num in triple_numbers:
        if num not in count_map:
            count_map[num] = 1
        else:
            count_map[num] += 1
    
    for key, value in count_map.items():
        if value == 2:
            return True
    return False

is_p = is_poor(list(map(int, input().split())))

if is_p:
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i > n or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

### FIXED CODE ###

N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i >= M or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])
from __future__ import print_function
import numpy as np
import sys

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

cnt=0
S=list(input())
eprint(S)

L=list()
L.append(S.pop())
while len(S):
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        eprint("S: " + str(S))
        eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[]:
            L.append(S.pop())
        cnt=cnt+2
        eprint("S: " + str(S))
        eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#


### FIXED CODE ###

from __future__ import print_function
import numpy as np
import sys

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

cnt=0
S=list(input())
# eprint(S)

L=list()
L.append(S.pop())
while len(S)!=0:
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[] and S!=[]:
            L.append(S.pop())
        cnt=cnt+2
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
def main():
 i = 0

 while True:
   i += 1
   n = input()
   if n == 0: break
   print('Case ' +str(i) +': ' + n)
main()



### FIXED CODE ###

case = 0
while 1:
    case += 1
    n = int(input())
    if n == 0: break
     
    print("Case {}: {}".format(case, n))
N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return int(a*b/GCD(a,b))


lcm=1
for a in A:
    lcm=LCM(lcm,a)

retval=0
for a in A:
    retval+=lcm/a
    retval=retval%mod

print(int(retval%mod))


### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return int(a*b//GCD(a,b))





lcm=1
for a in A:
    lcm=LCM(lcm,a)


retval=0
for a in A:
    retval+=lcm//a

print(int(retval%mod))
from fractions import Fraction

gcd = fractions.gcd

N, X = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]

def gcdList(numbers):
    if len(numbers) == 1:
        return abs(numbers[0])
    if len(numbers) == 2:
        return gcd(numbers[0], numbers[1])
    else:
        return gcdList([gcd(numbers[0], numbers[1])] + numbers[2:])

print(gcdList([_ - X for _ in x]))

### FIXED CODE ###

N, X = [int(_) for _ in input().split()]
xs = [abs(int(_) - X) for _ in input().split()]

def gcd(p, q):
    while q != 0:
        p, q = q, p % q
    return p

y = xs[0]
for i in range(N):
    if xs[i] % y != 0:
        y = gcd(y, xs[i])

print(y)
a, b, n = map(int, input().split())
ans = [0] * n
for i in range(n):
    ans[i] = (a * (i+1) / b) // 1 - a * (((i+1) / b) // 1)
print(int(max(ans)))

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
if b <= n:
    print(math.floor((a * (b-1)) / b) - a * math.floor((b-1) / b))
elif b > n:
    print(math.floor((a * (n)) / b) - a * math.floor((n) / b))
import heapq
N, K = map(int,input().split())
L1 = []
L2 = []
S = set()
val = 0

for _ in range(N):
    t, d = map(int,input().split())
    L1.append((d, t))

L1.sort(reverse = True)

for i in range(K):
    val += L1[i][0]
    if L1[i][1] in S:
        heapq.heappush(L2, -L1[i][0])
    else:
        S.add(L1[i][1])

ans = val + len(S) ** 2

for i in range(K, N):
    if not L1[i][1] in S:
        S.add(L1[i][1])
        val += heapq.heappop(L2)
        val += L1[i][0]
        ans = max(ans, val + len(S) ** 2)

print(ans)

### FIXED CODE ###

import heapq
N, K = map(int,input().split())
L1 = []
L2 = []
S = set()
val = 0

for _ in range(N):
    t, d = map(int,input().split())
    L1.append((d, t))

L1.sort(reverse = True)

for i in range(K):
    val += L1[i][0]
    if L1[i][1] in S:
        heapq.heappush(L2, L1[i][0])
    else:
        S.add(L1[i][1])

ans = val + len(S) ** 2

for i in range(K, N):
    if len(L2) == 0:
        break
    if not L1[i][1] in S:
        S.add(L1[i][1])
        val -= heapq.heappop(L2)
        val += L1[i][0]
        ans = max(ans, val + len(S) ** 2)

print(ans)
# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**5)

def dfs(num,log):
    visited[num]=min(log,visited[num])
    for item in way[num]:
        if visited[item]==10**7:
            dfs(item,log)
    return 

N,M=map(int,input().split())

visited=[10**7]*N
way=[[] for i in range(N)]
order=[]

for _ in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=min(X,Y),max(X,Y)
    order.append([X-1,Y-1,Z])

order.sort(key=lambda x:(x[0],x[1]))

for item in order:
    way[item[0]].append(item[1])
    way[item[1]].append(item[0])
    
for i in range(N):
    dfs(i,i)

visited=list(set(visited))
print(len(visited))

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**7)

def dfs(num,log):
    visited[num]=min(log,visited[num])
    for item in way[num]:
        if visited[item]==10**7:
            dfs(item,log)
    return 

N,M=map(int,input().split())

visited=[10**7]*N
way=[[] for i in range(N)]
order=[]

for _ in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=min(X,Y),max(X,Y)
    order.append([X-1,Y-1,Z])

order.sort(key=lambda x:(x[0],x[1]))

for item in order:
    way[item[0]].append(item[1])
    way[item[1]].append(item[0])
    
for i in range(N):
    dfs(i,i)

visited=list(set(visited))
print(len(visited))
if __name__ == '__main__':
  
	num = input()

	if int(num[0]) * int(num[1]) % 2 ==0:
		print("No")
	else:
  		print("Yes")

### FIXED CODE ###

if __name__ == '__main__':
  
	num = input().split()

	if int(num[0]) * int(num[1]) % 2 ==0:
		print("No")
	else:
  		print("Yes")
if __name__ == "__main__":
    n = int(input())
    if x<29:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n = int(input())
if n<30:
    print("No")
else:
    print("Yes")
h, w = map(int, raw_input().split())
S = [raw_input().split() for i in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if S[i][j] == "snuke":
            print "%s%d" % ("ABCDEFGHIJ"[j], i+1)


### FIXED CODE ###

h, w = map(int, raw_input().split())
S = [raw_input().split() for i in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if S[i][j] == "snuke":
            print "%s%d" % ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[j], i+1)
from collections import collector 
n=[] 
n=input()
p=counter(n). keys() 
print(p)

### FIXED CODE ###

x = len(set(list(map(int,input().split()))))
print(x)
import numpy as np

N, W=[int(i) for i in input().split()]
wv=[[int(i) for i in input().split()] for _ in range(N)]

dp=np.zeros((N,W+1)).astype("int64")


for i in range(N):
    for w in range(W+1):
        if i==0:
            if wv[i][0]<=w:
                dp[i][w]=wv[i][1]
        else:
            if w>=wv[i][0]:
                dp[i][w]=max(dp[i-1][w-wv[i][0]]+wv[i][1],dp[i-1][w])
            else:
                dp[i][w]=dp[i-1][w]

print(int(dp[-1].max())) 

### FIXED CODE ###



N, W=[int(i) for i in input().split()]
wv=[[int(i) for i in input().split()] for _ in range(N)]


dp=[[0]*(W+1) for _ in range(N)]

for i in range(N):
    for w in range(W+1):
        if i==0:
            if wv[i][0]<=w:
                dp[i][w]=wv[i][1]
        else:
            if w>=wv[i][0]:
                dp[i][w]=max(dp[i-1][w-wv[i][0]]+wv[i][1],dp[i-1][w])
            else:
                dp[i][w]=dp[i-1][w]

print(max(dp[-1]))
using System;
using System;
using System.Collections.Generic;
using System.Linq;


    class Solver5
    {
        /*
         * 
         * https://atcoder.jp/contests/abc115/tasks/abc115_d
         * 
         */
 public void Solve5()
        {
            var nx = u.readLongArrayBySplit();
			var n = nx[0];
            var x = nx[1];
            long ans = 0;

            while (true)
            {
                var thk = new long[5]{ 1, (long)Math.Pow(2,n + 1) - 3, 1, (long)Math.Pow(2, n + 1) - 3, 1 };
                var pc = new long[5] { 0, (long)Math.Pow(2, n ) - 1 , 1, (long)Math.Pow(2, n )- 1, 0 };
                for (int i = 0; i < 5; i++)
                {
                    if (x > thk[i])
                    {
                        x -= thk[i];
                        ans += pc[i];
                    }
                    else if (x < thk[i])
                    {
                        n--;
                        break;
                    }
                    else
                    {
                        ans += pc[i];
                        Console.WriteLine(ans.ToString());
                        return;
                    }
                }

            }

        }
        static void Main()
        {
            var solver = new Solver5();
            solver.Solve5();
        }
    }
    static class u
    {
      public static long[] readLongArrayBySplit() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }

### FIXED CODE ###

n,x = map(int,input().split())
 
#レベルnバーガーの構造は、1,2^(n+1)-3,1,2^(n+1)-3,1
 
ans = 0
x2 = x
k=n
while True:
  thk = [1,2**(k+1)-3,1,2**(k+1)-3,1]
  pc = [0,2**k-1,1,2**k-1,0]
  for i in range(5):
    x2-=thk[i]
    if x2<0:
      x2+=thk[i]
      k-=1
      break
    elif x2==0:
      ans+=pc[i]
      print(ans)
      exit()
    else:
      ans+=pc[i]
n = int(input())
dp = [0]*(n+1)
a = list(map(int, input().split()))
  
dp[1] = abs(a[1]-a[0])
for i in range(2,n+1):
  dp[i] =  min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]))
print(dp[n])
           

### FIXED CODE ###

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

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(a[1]-a[0])

for i in range(2, n):
    dp[i] = min([dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])])

print(dp[n-1])
a,b,c=map(str,input().split())
print(n)
if n%4==0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c=map(str,input().split())
n=int(a+b+c)
if n%4==0:
    print("YES")
else:
    print("NO")
height = map(int, raw_input().split())

height.sort()

for i in range(3):
  print height[9-i]

### FIXED CODE ###

s = []
for i in xrange(10):
	s.append(int(raw_input()))
s.sort()
s.reverse()
for i in xrange(3):
	print s[i]
from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '#']

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < w and -1 < x[1] < h, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    grid = [list(repeat('#', w)) for _ in range(h)]

    targets = get_targets(a_grid)

    while len(targets) != 0:
        t = targets.pop()
        arounds = get_arounds(t, h, w)
        if any([(a in targets) for a in arounds]):
            targets = list(filter(lambda e: e not in arounds), targets)
        else:
            print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '#']

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < h and -1 < x[1] < w, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    black_sq = get_targets(a_grid)

    if all([any([(sq in black_sq) for sq in get_arounds(bsq, h, w)]) for bsq in black_sq]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
print(count[0]*count[1]*count[2]-c)


### FIXED CODE ###

import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
if(len(count)==3):
    print(count[0]*count[1]*count[2]-c)
else:
    print(0)
k = int(input())
s = input()

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 10**6+5
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)

### FIXED CODE ###

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

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2 == 1:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 2000005
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)
input1 = input().split(' ')
input2 = input().split(' ')

if input1[2] == input2[0] :
    if input1[1] == input2[1] :
        if input1[0] == input2[2] :
            print("Yes")
        else :
            print("No")
    else :
        print("No")
else :
    print("No")

### FIXED CODE ###

input1 = input()
input2 = input()

if input1[::-1] == input2[::] :
    print("YES")
else :
    print("NO")
from math import ceil
n=int(input())
ans4=0
ans2=0
ans0=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    ans0+=1
if ans2>0:
  if ans0<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if ceil((ans0+ans4)/2)>=:ans0
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

from math import ceil
n=int(input())
ans4=0
ans2=0
ans0=0
a=list(map(int,input().split()))
for i in range(n):
  if a[i]%4==0:
    ans4+=1
  elif a[i]%2==0:
    ans2+=1
  else:
    ans0+=1
if ans2>0:
  if ans0<=ans4:
    print('Yes')
  else:
    print('No')
else:
  if ceil((ans0+ans4)/2)>=ans0:
    print('Yes')
  else:
    print('No')
contest = input()
if "ARC" == contest:
  print("ABC")
else
  print("ARC")

### FIXED CODE ###

contest = input()
if "ARC" == contest:
  print("ABC")
else:
  print("ARC")
S = list(map(int, input()))

count = 0
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    del S[i],S[i+1]
    count =2+count 
  else:
    if len(S)==i+1:
      print(count)
    else:
  		continue
    
print(count)
   


	

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  


### FIXED CODE ###

S = list(map(int, input()))

S_1 = [S[i] for i in range(len(S)) if S[i]==1]
S_0 = [S[i] for i in range(len(S)) if S[i]==0]

S_min = min(len(S_1), len(S_0))

print(2*S_min)
n,m,x = map(int,input().split())
a = input().split()
a += str(x) 
b = sorted(a).index(str(x))
if b <= (len(a)-1-b):
    print(b)
else:
    print(len(a)-1-b)


### FIXED CODE ###

n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))
def solve():
    A, B = map(int, input().split())
    s1 = tuple(map(int, input().split()))
    s2 = tuple(map(int, input().split()))
    result = 0

    for i in range(B):
        k = 0
        cnt = 0
        for j, n in enumerate(s2[i:]):
            while k < A and n != s1[k]:
                k += 1
            if n == s1[k]:
                cnt += 1
            if k == A:
                break
        if cnt > result:
            result = cnt

    print(result)


if __name__ == "__main__":
    solve()

### FIXED CODE ###

def solve():
    A, B = map(int, input().split())
    s1 = tuple(map(int, input().split()))
    s2 = tuple(map(int, input().split()))
    set1 = [0]*(A+1)
    set1[-1] = set()
    for i, n in enumerate(s1[::-1], start=2):
        set1[-i] = set1[-i+1] | {n}
    result = 0

    for i in range(B):
        k = 0
        cnt = 0
        for n in s2[i:]:
            if n not in set1[k]:
                break
            for m in s1[k:]:
                k += 1
                if n == m:
                    cnt += 1
                    break
        if cnt > result:
            result = cnt
        if result >= B-i:
            break
    print(result)


if __name__ == "__main__":
    solve()
input_arr = [int(x) for x in input().split()]
 
L = input_arr[0]
R = input_arr[1]
 
min_ans = 10**18
for i in range(L,R):
    for j in range(i+1,R+1):
      	ans = (i*j)%2019
        if ans < min_ans:
            min_ans = ans
        if min_ans == 0:
          break
print(min_ans)

### FIXED CODE ###

L,R = [int(x) for x in input().split()]
 
min_ans = 10**18

if R-L>=2019:
  min_ans=0
else:
  for i in range(L,R):
      for j in range(i+1,R+1):
          ans = (i*j)%2019

          if ans < min_ans:
              min_ans = ans
          if min_ans == 0:
              break
print(min_ans)
N, M = map(int, input().split())

L = []
R = []

for i in range(M):
    inp = input().split()
    L.append(inp[0])
    R.append(inp[1])
    
if max(L) <= min(R):
    print(min(R)-max(L)+1)
else:
    print(0)

### FIXED CODE ###

N, M = map(int, input().split())

L = []
R = []

for i in range(M):
    inp = input().split()
    L.append(int(inp[0]))
    R.append(int(inp[1]))
    
if max(L) <= min(R):
    print(min(R)-max(L)+1)
else:
    print(0)
x = input().split()

a = x[0]
b = x[1]

if a > b * 2:
  ret = a - b * 2
else:
  ret = 0
  
print(ret)

### FIXED CODE ###

x = input().split()
 
a = int(x[0])
b = int(x[1])
 
if a > b * 2:
  ret = a - b * 2
else:
  ret = 0
  
print(ret)
a,b=map(int,input().split())
if a=b:
  print('Draw')
elif a=1 or a>b:
  print('Alice')
elif b=1 or a<b:
  print('Bob')

### FIXED CODE ###

a,b=map(int,input().split())
if a==b:
  print('Draw')
elif a==1:
  print('Alice')
elif b==1:
  print('Bob')
elif a > b:
  print('Alice')
else:
  print('Bob')
# ABC144d


def main():
    import sys
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    a, b, x = map(int, input().split())
    if a*b*b/2 >= x:
        print(math.degrees(math.atan(b*b*a/2/x)))
        exit(0)
    print(math.degrees(atan((b-x/a/a)/a*2)))


if __name__ == '__main__':
    main()

### FIXED CODE ###

# ABC144d


def main():
    import sys
    import math
    import numpy as np
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    a, b, x = map(int, input().split())
    if x > a*a*b/2:
        print(np.rad2deg(np.arctan(2*(a*a*b-x)/(a*a*a))))
        # print(math.degrees(math.atan(2*(a*a*b-x)/(a*a*a))))
        exit(0)
    # print(math.degrees(math.atan(a*b*b/2/x)))
    print(np.rad2deg(np.arctan(a*b*b/2/x)))


if __name__ == '__main__':
    main()
from itertools import combinations
l, r = map(int, input().split())
n = list(combinations(range(l, r+1), 2))
ans=[]
for N in n:
    ans.append(N[0]*N[1]%2019)
print(min(ans))

### FIXED CODE ###

l, r=map(int,input().split())
if r-l>=2019:
    minimum=0
else:
    left,right=l%2019,r%2019
    minimum=2018**2
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            minimum=min(minimum,i*j%2019)
print(minimum)
#

import sys
input=sys.stdin.readline

def main():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    ans=[]
    for i in range(max(X,100-X)):
        if not X+i in p:
            ans+=[X+i]
        if not X-i in p:
            ans+=[X-i]
        if len(ans)>0:
            break
    print(min(ans))
    
if __name__=="__main__":
    main()


### FIXED CODE ###

#

import sys
input=sys.stdin.readline

def main():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    ans=[]
    for i in range(max(X,100-X)):
        if not X+i in p:
            ans+=[X+i]
        if not X-i in p:
            ans+=[X-i]
        if len(ans)>0:
            break
    if len(ans)==0:
        print(0)
    else:
        print(min(ans))
    
if __name__=="__main__":
    main()