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

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

a = l()

ans = a[0]

for i in range(1,n):
	if ans == -1:
		if a[i] == 0:
			ans *= 0
	ans *= a[i]
	if ans > 10**18:
		ans = -1

print(ans)



### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

a = l()

ans = a[0]

for i in range(1,n):
	if ans == -1:
		if a[i] == 0:
			ans *= 0
			break
	if ans != -1:
		ans *= a[i]
	if ans > 10**18:
		ans = -1

print(ans)
### BUGGY CODE ###

MOD = 10**9+7

S = list(input())
pre = [0]*13
now = [0]*13
pre[0]=1

for i in range(0,len(S),1):
    now =[0]*13
    if S[i]=="?":
        for k in range(0,10,1):
            for j in range(0,13,1):
                now[j] = (now[j] + pre[(j - (k*pow(10,len(S)-i-1,13))%13)%13])%MOD
    else:
        for j in range(0,13,1):
            now[j] = pre[(j - (int(S[i])*pow(10,len(S)-i-1,13))%13)%13]
    
    for j in range(0,13,1):
        pre[j]=now[j]

print(now[5])

### FIXED CODE ###

s = input()
 
mod = 10**9+7
n = len(s)
res = [1] + [0] * 12
for ss in s:
    dp = [0] * 13
    for i in range(13):
        dp[(10*i)%13] = res[i]
    dp += dp
 
    if ss == '?':
        for i in range(13):
            res[i] = sum(dp[i+4:i+14])
    else:
        for i in range(13):
            res[i] = dp[i+13-int(ss)]
    res = [v%mod for v in res]
print(res[5])
### BUGGY CODE ###

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

b = 1
for i in A[0:K]:
    b *= i

for i in range(N-K):
    a = 1
    for i in A[i+1:i+K+1]:
        a *= i
    if b < a :
        print("Yes")
    else:
        print("No")
    b = a


### FIXED CODE ###

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

result = []
for i in range(K, N):
    if A[i] > A[i - K]:
        result.append('Yes')
    else:
        result.append('No')
print(*result, sep='\n')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math

K = int(input())
ans_list = []
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans_list = [a, b, c]
            gcd_ans = ans_list[0]
            for item in ans_list:
                gcd_ans = math.gcd(gcd_ans, item)
            ans += gcd_ans
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
 
K = int(input())
ans_list = []
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans_list = [a, b, c]
            gcd_ans = ans_list[0]
            for item in ans_list:
                gcd_ans = math.gcd(gcd_ans, item)
            ans += gcd_ans
print(ans)
### BUGGY CODE ###

import queue
N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

visited = [False] * N
dist = [float('inf')] * N
rooms = [-1] * N
def bfs(u):
    q = queue.Queue()
    q.put((u, 0, -1))
    while not q.empty():
        (v, d, p) = q.get()
        visited[v] = True
        if dist[v] > d:
            dist[v] = d
            if p != -1:
                rooms[v] = p
        for e in edges[v]:
            if visited[e]:
                continue
            q.put((e, d + 1, v))

dist[0] = 0
bfs(0)
print("Yes")
for x in rooms[1:]:
    print(x + 1)

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

rooms = [-1] * N
def bfs(u):
    q = deque()
    q.append(u)
    while 0 < len(q):
        v = q.popleft()
        for e in edges[v]:
            if rooms[e] == -1:
                rooms[e] = v + 1
                q.append(e)

bfs(0)
print("Yes")
print(*rooms[1:], sep="\n")
### BUGGY CODE ###

import sys
from collections import deque

H, W, K = map(int, sys.stdin.readline().strip().split())
xs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())

m = []
for _ in range(H):
    m.append(list(map(str, sys.stdin.readline().strip())))

M = [[float('inf')] * W for _ in range(H)]


def bfs(x1, y1, d):
    q = deque()
    q.append((d, x1, y1))

    while q:
        d, x1, y1 = q.popleft()

        M[x1][y1] = d

        if (x1 == xg - 1) and (y1 == yg - 1):
            break

        for dx, dy in ([0, 1], [1, 0], [0, -1], [-1, 0]):
            k = 1
            while k <= K:
                x2 = x1 + dx * k
                y2 = y1 + dy * k
                if x2 < 0 or x2 >= H:
                    break
                if y2 < 0 or y2 >= W:
                    break
                if m[x2][y2] == '@':
                    break
                if M[x2][y2] < d + 1:
                    break
                if M[x2][y2] == d + 1:
                    continue

                q.append((d + 1, x2, y2))

                k += 1


if m[xs - 1][ys - 1] != '@':
    bfs(xs - 1, ys - 1, 0)

# for i in range(len(M)):
#     print(M[i])


ans = M[xg - 1][yg - 1]
if ans == float('inf'):
    print(-1)
else:
    print(ans)


### FIXED CODE ###

from collections import deque


def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
        y, x = queue.popleft()  # queueに入っていたものを消す。
        if [y, x] == [gy, gx]:  # もしゴールについていたならば、そのときの手数を出す。
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            l = 1
            while True:
                new_y, new_x = y + j * l, x + k * l
                if (0 <= new_y < H) and (0 <= new_x < W):
                    if maze[new_y][new_x] == "@":
                        break
                    elif visited[new_y][new_x] == -1:  # まだ来たことない点だったという条件
                        visited[new_y][new_x] = visited[y][x] + 1
                        queue.append([new_y, new_x])  # 新しい点を足す。
                    elif visited[new_y][new_x] < visited[y][x] + 1:
                        break
                else:
                    break
                l += 1
                if l == K + 1:
                    break


H, W, K = map(int, input().split())
# K = min(K, max(H, W))
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
C = [0] * H
for i in range(H):
    C[i] = str(input())
visited = [[-1] * W for i in range(H)]
bfs(C, visited, x1, y1, x2, y2)
# print(visited)
print(visited[x2][y2])
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
ans=[0]*n
for i in range(max(l)):
    ans[i]=l.count(i+1)
for j in range(n):
    print(ans[j])

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int,input().split()))
m=max(a)
c=collections.Counter(a)
c=c.most_common()
l=[0]*n
for i in range(len(c)):
    l[c[i][0]-1]=c[i][1]
print(l[0])
for j in range(1,n):
    print(l[j])
### BUGGY CODE ###

from itertools import permutations
N = int(input())
rn = [list(map(int,input().split())) for _ in range(N)]
bn = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for p in permutations(range(N)):
  ans = max(ans, sum([1 if rn[i][0] < bn[p[i]][0] and rn[i][1] < bn[p[i]][1] else 0 for i in range(N)]))
print(ans)


### FIXED CODE ###

N = int(input())
rn = [[True]+list(map(int,input().split())) for _ in range(N)]
bn = sorted([list(map(int,input().split())) for _ in range(N)])
rn.sort(key=lambda x: -x[2])
for bp in bn:
  bx,by = bp
  for rp in rn:
    f,rx,ry = rp
    if f and rx<bx and ry<by:
      rp[0] = False
      break
print(sum([0 if rp[0] else 1 for rp in rn]))
### BUGGY CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
print(ans[-1])

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(raw_input())
li = map(int, raw_input().split())

move_max = 0
inext = -1

for i in xrange(N-1):
    if i <= inext:
        continue
    move = 0
    tmp = li[i]
    
    for j in xrange(i+1,N):
        if tmp >= li[j]:
            tmp = li[j]
            move += 1
    	else:
            inext = move
            break
    if move > move_max:
        move_max = move

print move_max


### FIXED CODE ###

n = int(raw_input())
a = map(int, raw_input().split())
 
ans = 0
temp = 0
for i in xrange(n-1):
    if a[i] >= a[i+1]:
        temp = temp + 1
    else:
        ans = max(ans, temp) 
        temp = 0
 
print max(ans, temp)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = A
A = np.array(A)
B = np.array(B)
emp = np.zeros(N)
Amax_ind = np.argmax(A)
emp[Amax_ind:] = max(A)
A[Amax_ind:] = 0
while True:
    subAmax_ind = np.argmax(A)
    emp[subAmax_ind:Amax_ind] = max(A)
    A[subAmax_ind:Amax_ind] = 0
    Amax_ind = subAmax_ind
    if 0 not in emp:
        break
print(int(sum(emp-B)))

### FIXED CODE ###

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

ans = 0
cur_max = 0

for x in a:
    if cur_max > x:
        ans += cur_max - x
    cur_max = max(cur_max, x)

print(ans)
### BUGGY CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)

import math
mod = 10 ** 9 + 7

n = int(input())
a = [int(i) for i in input().split()]
tmp = a[0]
set_v = a[0]
pairwise = True
prime_list = set([])
for i in range(1, n):
    prime = prime_factorize(a[i])
    set_v = math.gcd(set_v, a[i])
    for p in prime:
        if p in prime_list:
            pairwise = False
        prime_list.add(p)
if pairwise == True:
    ans = 'pairwise coprime'
elif set_v == 1:
    ans = 'setwise coprime'
else:
    ans = 'not coprime'
print(ans)

### FIXED CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)

import math
mod = 10 ** 9 + 7

n = int(input())
a = [int(i) for i in input().split()]
tmp = a[0]
set_v = a[0]
pairwise = True
prime_list = set([])
for i in range(1, n):
    prime = prime_factorize(a[i])
    set_v = math.gcd(set_v, a[i])
    for p in prime:
        if p in prime_list:
            pairwise = False
        prime_list.add(p)
if pairwise == True:
    ans = 'pairwise coprime'
elif set_v == 1:
    ans = 'setwise coprime'
else:
    ans = 'not coprime'
print(ans)
### BUGGY CODE ###

q = int(input())
for i in range(q):
    x = input()
    y = input()
    n = len(x)
    m = len(y)
    dp = [0]*((n+1)*(m+1))
    for i in range(n):
        for j in range(m):
            a = (n+1)*(j+1)+i+1
            if x[i] == y[j]:
                b = (n+1)*j+i
                dp[a] = dp[b]+1
            else:
                c = (n+1)*j+i+1
                d = (n+1)*(j+1)+i
                dp[a] = max(dp[c],dp[d])
    print(dp[-1])


### FIXED CODE ###

def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
  for y in range(k + 1):
    for z in range(k + 1):
      if x + y + z == s:
        ans += 1
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
  for y in range(k + 1):
    if x + y > s:
      break
    z = s - x - y
    if 0 <= z <= k:
      ans += 1
      
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(Ai) for Ai in input().split()]

count = 0
for i, Ai in enumerate(A):
    found = False
    for j, Aj in enumerate(A):
        if i != j and Ai % Aj == 0:
            found = True
            break
    if not found:
        count += 1

print(count)


### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(Ai) for Ai in input().split()]

counter = Counter(A)

dp = [1] * (max(A) + 1)
for Ai in A:
    for j in range(Ai * 2, len(dp), Ai):
        dp[j] = 0

print(sum([dp[Ai] == 1 and counter[Ai] == 1 for Ai in A]))
### BUGGY CODE ###

import sys
import itertools
import collections

input = sys.stdin.readline

def main():
    k, q = map(int, input().split())
    d = list(map(int, input().split()))
    for _ in range(q):
        n, x, m = map(int, input().split())
        dmodm = [y%m for y in d]
        kmod = (n-1)%k
        kdiv = (n-1)//k
        dmodmCounter = collections.Counter(dmodm)
        dmodmkCounter = collections.Counter(dmodm[:(kmod)])
        dmodcum = [0] + list(itertools.accumulate(dmodm))
        p0 = dmodmCounter[0] * (kdiv) + dmodmkCounter[0]
        an = x + dmodcum[kmod] + dmodcum.pop() * (kdiv) 
        p1 = an//m - x//m
        ans = n - (p0 + p1) - 1
        print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import itertools
import collections

input = sys.stdin.readline

def main():
    k, q = map(int, input().split())
    d = list(map(int, input().split()))
    for _ in range(q):
        n, x, m = map(int, input().split())
        dmodm = [y%m for y in d]
        kmod = (n-1)%k
        kdiv = (n-1)//k
        cnt = 0; cntm = 0
        for i in range(k):
            cnt += dmodm[i] == 0
            cntm += (dmodm[i] == 0 and i < kmod)
        #dmodmCounter = collections.Counter(dmodm)
        #dmodmkCounter = collections.Counter(dmodm[:kmod])
        dmodcum = list(itertools.accumulate(dmodm))
        #p0 = dmodmCounter[0] * kdiv + dmodmkCounter[0]
        p0 = cnt * kdiv + cntm
        an = x + (kmod != 0) * dmodcum[kmod-1] + dmodcum.pop() * kdiv
        p1 = an//m - x//m
        ans = n - (p0 + p1) - 1
        print(ans)

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

# 2019-11-19 10:28:31(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 



INF = 10 ** 12

# V: number of vertices, cost: graph(dist[u][v] / time[u][v] / ...)
def warshall_floyd(V, cost):
    min_cost = cost
    for w in range(1, V+1): # way-point
        for s in range(1, V+1): # start
            for t in range(1, V+1): # goal
                min_cost[s][t] = min(min_cost[s][t], min_cost[s][w] + min_cost[w][t])
    return min_cost


def main():
    # stdin
    n, m, l = map(int, sys.stdin.readline().split())
    dist = [[None for _ in range(n+1)]] + [[None] + [INF for _ in range(n)] for _ in range(n)]
    for s in range(1,n+1):
        dist[s][s] = 0
    for _ in range(m):
        u, v, d = map(int, sys.stdin.readline().split())
        dist[u][v], dist[v][u] = min(dist[u][v], d), min(dist[v][u], d)
        # 問題の条件より、２点間の直経路が一つだけとは限らないので複数あった場合に最短を選択する処理
    
    q = int(sys.stdin.readline().rstrip())
    st = map(int, sys.stdin.read().split())
    st = zip(st, st)



    shortest_dist = warshall_floyd(n, dist)


    filling_times = [[None for _ in range(n+1)]] + [[None] + [INF for _ in range(n)] for _ in range(n)]
    for s in range(1, n+1):
        for t in range(1, n+1):
            if s == t:
                filling_times[s][t] = 0
            elif shortest_dist[s][t] <= l:
                filling_times[s][t] = 1
    
    min_filling_times = warshall_floyd(n, filling_times)
    for s, t in st:
        # 最初は満タンのため-1
        print(min_filling_times[s][t] - 1 if not min_filling_times[s][t] == INF else -1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# 2019-11-19 10:28:31(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np 


def main():
    n, m, l = map(int, sys.stdin.readline().split())
    ABCQST = np.array(sys.stdin.read().split(), np.int64)
    ABC = ABCQST[:m * 3]
    A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
    ST = ABCQST[m * 3 + 1:]
    S, T = ST[::2], ST[1::2]

    dist = csr_matrix((C, (A, B)), (n+1, n+1))
    min_dist = floyd_warshall(dist, directed=False)

    filling_times = np.full((n+1, n+1), np.inf)
    np.diagonal(filling_times, 0)
    filling_times[min_dist <= l] = 1

    min_filling_times = floyd_warshall(filling_times, directed=False)

    min_filling_times[min_filling_times == np.inf] = 0
    # 最後に-1する
    min_filling_times = min_filling_times.astype(int)

    res = min_filling_times[S, T] - 1
    print('\n'.join(res.astype(str)))


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

from sys import stdin
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = ["@"]
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        ccnt = 0
        if data[1] == "1":
            if cnt % 2 == 0:
                #s = "".join([data[2],s])
                s.insert(0,data[2])
            else:
                #s = "".join([s,data[2]])
                s.append(data[2])
        else:
            if cnt % 2 == 0:
                #s = "".join([s,data[2]])
                s.append(data[2])
            else:
                #s = "".join([data[2],s])
                s.insert(0,data[2])
    else:
        cnt += 1
s = "".join(s)
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)

### FIXED CODE ###

from sys import stdin
from collections import deque
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = deque(["@"])
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        if data[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(data[2])
            else:
                s.append(data[2])
        else:
            if cnt % 2 == 0:
                s.append(data[2])
            else:
                s.appendleft(data[2])
    else:
        cnt += 1
s = "".join(s)
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)
### BUGGY CODE ###

from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(50, K)):
    A = calc_imos(A)
print(*A, sep=' ')

### FIXED CODE ###

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

for i in range(min(k, 50)):
    b = [0] * (n + 1)
    for j in range(n):
        l = max(0, j - a[j])
        r = min(n - 1, j + a[j])
        b[l] += 1
        b[r + 1] -= 1
    for m in range(n):
        b[m + 1] += b[m]
    a = b[:-1]
print(*a)
### BUGGY CODE ###


from bisect import bisect, bisect_left
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

H, W = inpl()
#A = [[int(s == "#") for s in input()] for _ in range(H)]

check = set()
colored = set()
for h in range(H):
    for w, c in enumerate(input()):
        if c == "#":
            check.add((h, w))
colored.update(check)

ans = 0
while True:
    check2 = set()
    for (h, w) in check:
        for dh, dw in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
            nh, nw = min(max(h+dh, 0), H-1), min(max(w+dw, 0), W-1)
            if not (nh, nw) in colored:
                check2.add((nh, nw))
    check = check2
    if len(check):
        colored.update(check)
        ans += 1
    else:
        print(ans)
        break

### FIXED CODE ###


from collections import defaultdict, deque
def inpl(): return list(map(int, input().split()))

H, W = inpl()
searched = [[10**9]*(W+2) for _ in range(H+2)]

for h in range(H+2):
    searched[h][0] = 0
    searched[h][-1] = 0
for w in range(W+2):
    searched[0][w] = 0
    searched[-1][w] = 0

Q = deque()
for h in range(H):
    for w, c in enumerate(input()):
        if c == "#":
            searched[h+1][w+1] = 0
            Q.append((h+1, w+1, 0))

while Q:
    h, w, c = Q.popleft()
    if searched[h][w] < c:
        continue
    for dh, dw in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        nh, nw = h+dh, w+dw
        if searched[nh][nw] > c+1:
            searched[nh][nw] = c+1
            Q.append((nh, nw, c+1))

print(max(map(max, searched)))
### BUGGY CODE ###

def main():
     import sys
     input=sys.stdin.readline

     ans=0
     N,M=map(int,input().split())
     Ar=[]
     for _ in range(M):
           Ar.append([])
     for _ in range(N):
          A,B=map(int,input().split())
          if A <= M:
              Ar[A-1].append(B)
     An=[]
     for i in range(M):
          An += Ar[i]
          if len(An)>0:
              An.sort()
              ans+=An.pop(len(An)-1) 
     print(ans)

if __name__ =='__main__':
    main()

### FIXED CODE ###

import heapq
N , M = map(int , input().split())
jobs = [list(map(int , input().split())) for _ in range(N)]
jobs.sort()

q = []
index = 0
ans = 0
for limit in range(1 , M + 1):
    while index < N:
        time =jobs[index][0]
        reward = jobs[index][1]
        if limit >= time:
            heapq.heappush(q , -reward)
            index += 1
        else:
            break
    #print(q)
    if len(q) != 0:
        tmp = heapq.heappop(q)
        ans -= tmp

print(ans)