Harryxun/stf_run huggingface dataset:
#coding: utf-8
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * AB[0][1]
else:
  i = 0
  while M >= 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M < 0:
      money += AB[i][0] * M
    i += 1
print(money)

### FIXED CODE ###

#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M > 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)
import sys

n, we = map(int, input().split())

cf=[(0, 0)]*n

cf = sorted( [[int(x) for x in sys.stdin.readline().split())] for _ in range(n)] )

dp=[0]*(we+1)

best=0
cnt=1
lim=0

for w,c in cf:
    cnt=cnt+w
    lim=min(cnt, we-w)
    for j in range(lim, -1, -1):
        if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c

print(max(dp))

### FIXED CODE ###

n, we = map(int, input().split())

cf=[(0, 0)]*(n+1)

for i in range(1, n+1):
    cf[i] = tuple( map(int, input().split()) )

dp=[[0]*(we+1) for _ in range(n+1)]

best=0

for i in range(1, n+1):
    for j in range(cf[i][0]):
        dp[i][j]=dp[i-1][j]
    for j in range(cf[i][0], we+1):
        dp[i][j]=max( dp[i][j-1], dp[i-1][j], dp[i-1][j-cf[i][0]]+ cf[i][1] )
    best=max(best, dp[i][we])


print(best)

# for i in range(1, n+1): print( dp[i], '\n' )
pyramid=[]
if n==1:
  x,y,h=map(int,input().split())
  print(x,y,h)
  return
else:
  x,y,h=map(int,input().split())
  pyramid.append([x,y,h])
ans=[[0 for i in range(101)] for i in range(101)]
flag=1
for i in range(n):
  if pyramid[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        H=pyramid[i][2]+abs(pyramid[i][0]-cx)+abs(pyramid[i][1]-cy)
        if flag==1:
          ans[cx][cy]=H
        else:
          if ans[cx][cy]!=H:
            ans[cx][cy]=0
  flag=0
for i in range(101):
  for j in range(101):
    if ans[i][j]!=0:
      print(i,j,ans[i][j])


### FIXED CODE ###

from sys import exit
n=int(input())
pyramid=[]
for i in range(n):
  x,y,h=map(int,input().split())
  pyramid.append([x,y,h])
flag=0
for i in range(n):
  if flag==0 and pyramid[i][2]!=0:
    flag=-1
  elif flag==-1 and pyramid[i][2]!=0:
    flag=1
if flag==-1:
  for i in range(n):
    if pyramid[i][2]!=0:
      print(pyramid[i][0],pyramid[i][1],pyramid[i][2])
      exit()
ans=[[0 for i in range(101)] for i in range(101)]
for i in range(n):
  if pyramid[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        H=pyramid[i][2]+abs(pyramid[i][0]-cx)+abs(pyramid[i][1]-cy)
        if flag==1:
          ans[cx][cy]=H
        else:
          if ans[cx][cy]!=H:
            ans[cx][cy]=0
    flag=0
for i in range(101):
  for j in range(101):
    if ans[i][j]!=0:
      print(i,j,ans[i][j])
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n - sum(a) >= 0:
    print(n - sum(a))
else:
    print(-1)


### FIXED CODE ###

import math
r = int(input())
print(2 * r * math.pi)
i = 0

while True:
 n = int(input())
  if n == 0:break

   print("Case {}: {}".format(i, n))
   i += 1

### FIXED CODE ###

i = 0

while True:
 n = int(input())
 i += 1
 if n == 0:
  break
 print("Case {}: {}".format(i, n))
# https://atcoder.jp/contests/abc099/tasks/abc099_d
# さまざまな合わせ技
# ダイクストラ、全探索

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため



# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations

# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse import csr_matrix, lil_matrix
# 0 まずはダイクストラでX→Yの最小コストを求めておく
# 1 座標ごとに3つのグループわけができる(n=1のときだけ場合分け
# 2 グループごとに色をカウント
# 3 各グループの色を仮定して全探索

N, C = read_ints()
D = read_matrix(C)
# D = csr_matrix(D)
# D = dijkstra(D)


# 1 座標のグループわけ
Cmap = read_matrix(N)
lsbymod = defaultdict(lambda: [])
for i in range(N):
    for j in range(N):
        lsbymod[(i + j + 2) % 3].append(Cmap[i][j] - 1)

# グループごとに色のカウント
for k, v in lsbymod.items():
    lsbymod[k] = Counter(v)

# 各グループの色を仮定して全探索


# print(D)
# print(lsbymod)


def ret_score(*arg):
    # 各仮定から違和感を計算
    ret = 0
    for i in range(3):
        for k, v in lsbymod[i].items():
            ret += v * D[k][arg[i]]
    return ret


ans = 2**63
for a, b, c in permutations(range(C), 3):
    # print(a, b, c, ret_score(a, b, c))
    ans = min(ans, ret_score(a, b, c))

print(ans)


### FIXED CODE ###

# https://atcoder.jp/contests/abc099/tasks/abc099_d
# さまざまな合わせ技
# ダイクストラ、全探索

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため



# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations

# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse import csr_matrix, lil_matrix
# 0 まずはダイクストラでX→Yの最小コストを求めておく #えーーーーこれ想定されてないの？
# 1 座標ごとに3つのグループわけができる(n=1のときだけ場合分け
# 2 グループごとに色をカウント
# 3 各グループの色を仮定して全探索

N, C = read_ints()
D = read_matrix(C)
# D = csr_matrix(D)
# D = dijkstra(D)


# 1 座標のグループわけ
Cmap = read_matrix(N)

if N == 1:
    print(0)
    exit()

lsbymod = defaultdict(lambda: [])
for i in range(N):
    for j in range(N):
        lsbymod[(i + j + 2) % 3].append(Cmap[i][j] - 1)

# グループごとに色のカウント
for k, v in lsbymod.items():
    lsbymod[k] = Counter(v)

# 各グループの色を仮定して全探索


# print(D)
# print(lsbymod)


def ret_score(*arg):
    # 各仮定から違和感を計算
    ret = 0
    for i in range(3):
        for k, v in lsbymod[i].items():
            ret += v * D[k][arg[i]]
    return ret


ans = 2**63
for a, b, c in permutations(range(C), 3):
    # print(a, b, c, ret_score(a, b, c))
    ans = min(ans, ret_score(a, b, c))

print(ans)
from sys import stdin
from math import factorial

if __name__ == '__main__':

    N, K = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = 1000000007
    r = 0
    while True:
        r += 1
        n = N - K + 1

        if n - r < 0:
            break

        ret = factorial(n) // factorial(r) // factorial(n - r)
        ret2 = factorial(K-1) // factorial(r-1) // factorial((K - 1) - (r - 1))

        print((ret * ret2) % tmp)



### FIXED CODE ###

from sys import stdin
from collections import Counter

S = stdin.readline().rstrip()
cnt = Counter(S)

if len(cnt.keys()) == 2 and set(cnt.values()) == {2}:
    print('Yes')
else:
    print('No')
req = int(input())
count = 0
p = 100
while P < req:
  p += int(p/100)
  count +=1
  
print(count)


### FIXED CODE ###

req = int(input())
count = 0
p = 100
while p < req:
  p = p * 101//100
  p = int(p)
  count +=1
  
print(count)
import math
x=int(input())
pi=math.pi
print(round(2*x*pi,6),round(x*x*pi,6))

### FIXED CODE ###

x=float(input())
pi=3.141592653589793
print(str(round(x*x*pi,6))+" "+str(round(2*x*pi,6)))
a = [int(i) for i in input().split()]
print(" ".join(sorted(a)))

### FIXED CODE ###

a = [int(i) for i in input().split()]
a.sort()
print(a[0],a[1],a[2])
(n, x) = list(map(int, input().split()))
x_list = list(map(int, input().split()))

x_list.append(x)
x_list.sort()

min_diff = 999_999_999_999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()


### FIXED CODE ###

(n, x) = list(map(int, input().split()))
x_list = list(map(int, input().split()))

if x in x_list:
    pass
else:
    x_list.append(x)
    x_list.sort()

min_diff = 99999999999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()
print(1)
N, X, T = [int(i) for i in input().spilt()]

ans = 0

if N % X == 0:
  ans = (N // X) * T
else :
  ans = ((N // X) + 1) * T 

print(ans)

### FIXED CODE ###

N, X, T = [int(i) for i in input().split()]

q, r = divmod(N, X)

output = 0
if r > 0:
    output = (q+1) * T
else :
    output = q * T
    
print(output)
n = int(input())
s = str(input())
ans = 0

for i in range(1,len(s)):
    #print(t[:i], t[i:])
    left = list(t[:i])
    right = list(t[i:])
    kyoutuu = set(left) & set(right)
    ans = max(ans,len(list(kyoutuu)))
print(ans)

### FIXED CODE ###

n = int(input())
t = str(input())
ans = 0
for i in range(1,len(t)):
    #print(t[:i], t[i:])
    left = list(t[:i])
    right = list(t[i:])
    #print(left,right)
    kyoutuu = set(left) & set(right)
    j = len(list(kyoutuu))
    if ans < j:
        ans = j
print(ans)
if T[:-1]==S:    
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s=input()
t=input()
if t[:-1]==s:
    print("Yes")
else:
    print("No")
n = int(input())
a_list = list(map(int,input().split()))
c = -1
k = 0
for i in range(1,n+1):
  if not i in a_list:
    k = i
    break
  a_list = a_list[c+1:]
  c = a_list.index(i)
if k == 1:
  print(-1)  
elif k > 0:
  print(n-k+1)
else:
  print(0)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
h = 0
for i in range(0,n):
  if a[i] != i-h+1:
    h += 1
if h == n:
  print(-1)
else:
  print(h)
def calc(a):
  a = int(input())
  for a4 in range(26):
    for a7 in range(16):
      if a4*4+a7*7 is a:
        return "Yes"
  return "No"

if __name__ == '__main__':
  calc(int(input())
      

### FIXED CODE ###

def calc(a):
  for a4 in range(26):
    for a7 in range(16):
      if a4*4+a7*7 == a:
        return "Yes"
  return "No"

if __name__ == '__main__':
  print(calc(int(input())))
import sys
input=sys.stdin.buffer.readline
s1 = input()
s2 = input()
n, m = len(s1), len(s2)
dp = [[0]*(m+1) for _ in range(n+1)]
prev = dp[0]
for i in range(1,n+1):
    dpi = dp[i]
    for j in range(1, m+1):
        if s1[i-1] == s2[j-1]:
            dpi[j] = 1 + prev[j-1]
        else:
            dpi[j] = max(prev[j], dpi[j-1])
    prev = dpi
res = ''
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res = s1[i-1] + res
        i -= 1
        j -= 1
print(res)

### FIXED CODE ###

s1 = list(input())
s2 = list(input())
n = len(s1)
m = len(s2)
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1, m+1):
        if s1[i-1] == s2[j-1]:
            dp[i][j] = 1 + dp[i-1][j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
res = []
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res.append(s1[i-1])
        i -= 1
        j -= 1
print(''.join(res[::-1]))
N = int(input())

dp = [10**5]*(N+1)
dp[0] = 0
dp[1] = 1
s = 6
n = 9
for i in range(2,N+1):
    if 6*s <= i:
        s *= 6
    if 9*n <= i:
        n *= 9
    dp[i] = min(dp[i-1], dp[i-s], dp[i-n])+1
print(dp[N])

### FIXED CODE ###

N = int(input())

dp = [10**5]*(N+1)
dp[0] = 0
dp[1] = 1
s = 6
n = 9
for i in range(2,N+1):
    if 6*s <= i:
        s *= 6
    if 9*n <= i:
        n *= 9
    if i < 6:
        dp[i] = dp[i-1]+1
    elif i < 9:
        dp[i] = min(dp[i-1], dp[i-s])+1
    else:
        dp[i] = min(dp[i-1], dp[i-s], dp[i-n])+1
print(dp[N])
N=int(input())
a=list(input())

r=a.count('R')
g=a.count('G')
b=a.count('B')
N=len(a)
s=0
for i in range(N-1):
    for j in range(i+1, N):
        if 2*j-i < N:
            if a[i] !=a[j] and a[j]!=a[2*j-i] and a[2*j-i]!=a[i]:
                s+=1

n=r*g*b-s
print(n)

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())


a=N%10
b=((N-a)/10)%10
c=(N-10*b-a)/100
n=[a,b,c]
if 7 in n:
    print('Yes')

else:
    print('No')
from functools import reduce
from operator import mul

mod = 10**9 + 7

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

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

if N == K:
    print(reduce(mul, A)%mod)

else:

    AP = []
    AM = []
    for i in A:
        if i < 0:
            AM.append(i)
        else:
            AP.append(i)
            
    if len(AP) == 0 and K%2 != 0:
        AM.sort()
        AM[:K]
        print(reduce(mul, AM)%mod)

    else:
        
        AP.sort(reverse=True)
        AM.sort()

        ans = 1
        p = 0
        m = 0
        cnt = 0
        while True:
            if (p+1 <= len(AP) and AP[p]*AP[p+1] >= AM[m]*AM[m+1]) or (K - cnt) == 1:
                ans *= (AP[p]*AP[p+1])
                p += 2
                cnt += 2
            if m+1 <= len(AM):
                ans *= (AM[m]*AM[m+1])
                m += 2
                cnt += 2 

            if cnt == K:
                print(ans%mod)
                break

### FIXED CODE ###

from bisect import bisect_left,bisect_right
p=10**9+7
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
pi=1
ni=0
ans=1
i=0
while i<k-1:
  if a[ni]*a[ni+1]>a[-pi]*a[-pi-1]:
    ans=ans*a[ni]*a[ni+1]%p
    ni+=2
    i+=2
  else:
    ans=ans*a[-pi]%p
    pi+=1
    i+=1
if i==k-1:
  ans=ans*a[-pi]%p
if a[-1]<0 and k%2==1:
  ans=1
  for i in a[n-k:]:
    ans=ans*i%p
print(ans)
n,*a=map(int,open(0).read().split())
u=d=z=r=0
for i,j in zip(a[:n],a[n:]):
    if j-i>0:u+=(j-i)//2*2;r+=(j-i)%2
    elif j-i==0:z+=1
    else:d+=[j-i]
print("Yes" if u+2*d>=0 else "No")

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
u=d=z=r=0
for i,j in zip(a[:n],a[n:]):
    if j-i>0:u+=(j-i)//2*2;r+=(j-i)%2
    elif j-i==0:z+=1
    else:d+=j-i
print("Yes" if u+2*d>=0 else "No")
n = int(input())
def f(x):
  for k in range(2, int(sqrt(x)) + 1):
    if x % k != 0:
      continue
      return False
    return True
  i = n
while 1:
  if f(i):
    print(i)
    break
  i += 1

### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def primes(n):
    """ 
    Input n>=6, Returns a list of primes, 2 <= p < n 
    6以上の数であれば p (素数) <= n のlistを返す 
    :param int n:
    :rytpe list:
    """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#solve
def solve():
    x = II()
    p = primes(10 ** 6)
    print(p[bisect_left(p, x)])
    return


#main
if __name__ == '__main__':
    solve()
# coding: utf-8

n = int(input().rstrip())

numbers = list(reversed(sorted(map(int, input().rstrip().split(" ")))))

ans = 0
for i in range(n):
    ans += numbers[n*i+1]

print(ans)


### FIXED CODE ###

# coding: utf-8

n = int(input().rstrip())

numbers = list(reversed(sorted(map(int, input().rstrip().split(" ")))))

ans = 0
for i in range(n):
    ans += numbers[i*2+1]

print(ans)
import math
print(2*math.pi*int(input()))


### FIXED CODE ###

a, b = input().split()
lis = list(map(int, input().split()))
print(int(a) - sum(lis) if int(a) >= sum(lis) else "-1")
a,b = map(int, input().split())
print(max([a+b, a-b, a×b]))

### FIXED CODE ###

a,b = map(int, input().split())
print(max([a+b, a-b, a*b]))
a,b = map(input().split())
print("H" if a==b=="H" or a==b=="D" else "D")

### FIXED CODE ###

a,b = input().split()
print("H" if a==b=="H" or a==b=="D" else "D")
n = int(input())
dic = {}
for i in range(n+1):
    if i <= 1: continue
    ai = int(input())
    if ai in dic:
        dic[ai].append(i)
    else:
        dic[ai] = [i]

def dfs(nxt):
    lst = []
    if nxt in dic:
        while dic[nxt] != []:
            child = dic[nxt].pop()
            tempmax = dfs(child)
            lst.append(tempmax)
    else:
        return 0
    lst.sort(reverse=True)
    for i in range(len(lst)):
        lst[i] += i+1
    return max(lst)

ans = dfs(1)
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

n = int(input())
dic = {}
for i in range(n+1):
    if i <= 1: continue
    ai = int(input())
    if ai in dic:
        dic[ai].append(i)
    else:
        dic[ai] = [i]

def dfs(nxt):
    lst = []
    if nxt in dic:
        while dic[nxt] != []:
            child = dic[nxt].pop()
            tempmax = dfs(child)
            lst.append(tempmax)
    else:
        return 0
    lst.sort(reverse=True)
    for i in range(len(lst)):
        lst[i] += i+1
    return max(lst)

ans = dfs(1)
print(ans)
n = int(input)
p = list(map(int. input().split()))
ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    if (p[i-1] < p[i] and p[i+1] > p[i]) or (p[i-1] > p[i] and p[i+1] < p[i]):
        ans += 1
print(ans)
n, d = list(map(int, input().split()))
p = []
ans = 0
for i in n:
  p.append(list(map(int, input().split())))
  for j in range(i):
    s = 0
    for k in d:
      s += (p[i] - p[j]) ** 2
    t = int(s ** 0.5 + 1e-7)
    if t * t == s:
      ans += 1
print(ans)

### FIXED CODE ###

n, d = list(map(int, input().split()))
p = []
ans = 0
for i in range(n):
  p.append(list(map(int, input().split())))
  for j in range(i):
    s = 0
    for k in range(d):
      s += (p[i][k] - p[j][k]) ** 2
    t = int(s ** 0.5 + 1e-7)
    if t * t == s:
      ans += 1
print(ans)
st = []
n = raw_input()

for s in n:
	st.append(s)

s.sort()
a = int("".join())
b = int("".join(s[::-1]))

print b - a

### FIXED CODE ###

i = int(raw_input())

while (i):
	i -= 1
	st = []
	n = raw_input()

	for s in n:
		st.append(s)

	st.sort()
	a = int("".join(st))
	b = int("".join(st[::-1]))

	print b - a
M = [int(input()) for i in range(5)]
T = M[:]
tmp = 10
for i in range(5):
    if tmp > M[i] % 10 > 0:
        tmp = M[i] % 10
        c = i
    M[i] = ((M[i] - 1) // 10 + 1) * 10
M[c] = T[c]
print(sum(M))

### FIXED CODE ###

M = [int(input()) for i in range(5)]

a = [((i - 1) // 10 + 1) * 10 for i in M]
b = [(i - 1) % 10 for i in M]

ans = sum(a) + min(b) - 9
print(ans)
class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]

        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
c = Combination(1000000)
ans = 0
for r in range(r1, r2 + 1):
    temp = c(c2 + r + 1, r + 1) - c(c1 + r + 1 - 1, r + 1)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)


### FIXED CODE ###

class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]

        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
c = Combination(2000006)
ans = 0
for r in range(r1, r2 + 1):
    temp = c(c2 + r + 1, r + 1) - c(c1 + r + 1 - 1, r + 1)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)
S = list(input())
N = len(S)
for i in range(N):
    if S[i] is not 'A' or 'T' or 'G' or 'C':
        S.remove(S[i])
print(len(S))

### FIXED CODE ###

S = list(input())
N = len(S)
H = list('ATGC')
m = 0
ans = 0
for i in range(N):
    if S[i] in H:
        m += 1
        if ans < m:
            ans = m
    else:
        m = 0
print(ans)
a,p=list(map(int, input().split()))
print((3a+p)//2)

### FIXED CODE ###

a,p=map(int, input().split())
print((3*a+p)//2)
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in A:
    for b in B:
        for c in C:
            if 500*(a+1)+100*(b+1)+50*(c+1) == X:
                ans += 1
print(ans)

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*(a)+100*(b)+50*(c) == X:
                ans += 1
print(ans)
n, m = map(int,input().split())
 
l_p = 1
r_p = n
 
for j in range(m+1):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

print(a)

### FIXED CODE ###

n, m = map(int,input().split())
 
l_p = 1
r_p = n
 
for j in range(m):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

if a > 0:
  print(a)
else:
  print(0)