Harryxun/stf_run huggingface dataset:
N = int(input())
A = list(map(int, input().split()))

ans = []
mx = max(A)
mi = min(A)

if abs(mi) > abs(mx):
    x = A.index(mi)
    for y in range(N):
        if y == x:
            continue
        A[y] += mi
        ans.append((x, y))
if abs(mx) >= abs(mi):
    x = A.index(mx)
    for y in range(N):
        if x == y:
            continue
        A[y] += mx
        ans.append((x, y))

for i in range(N - 1):
    l, r = A[i], A[i + 1]

    if l > r:
        if r > 0:
            A[i + 1] += l
            ans.append((i, i + 1))
        if l < 0:
            A[i] += r
            ans.append((i + 1, i))

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

if list(sorted(A)) != A:
    print(A)
    1 / 0


### FIXED CODE ###

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

ans = []
mx = max(A)
mi = min(A)

if mx * mi < 0:
    if abs(mi) > abs(mx):
        x = A.index(mi)
        for y in range(N):
            if y == x:
                continue
            A[y] += mi
            ans.append((x, y))
    else:
        x = A.index(mx)
        for y in range(N):
            if x == y:
                continue
            A[y] += mx
            ans.append((x, y))

for i in range(N - 1)[::(-1)**(min(A) < 0)]:
    l, r = A[i], A[i + 1]

    if l > r:
        if r >= 0:
            A[i + 1] += l
            ans.append((i, i + 1))
        elif l <= 0:
            A[i] += r
            ans.append((i + 1, i))

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

if list(sorted(A)) != A:
    print(A)
    1 / 0
n,k=map(int,input().split())
v=list(map(int,input().split()))

m=min(n,k)
ans=0

for i in range(m):
    for j in range(i):
        q=[]
        tmp=0
        for k in range(j):
            q.append(v.pop(0))
        for k in range(i-j):
            q.append(v.pop(-1))
        q.sort()
        for l in range(len(q)):
            if q[i]>0:
                tmp+=q[i]
        ans=max(ans,tmp)
print(ans)
  

### FIXED CODE ###

n,ki=map(int,input().split())
v=list(map(int,input().split()))

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
print(ans)
L = 1000000
n,c = map(int, input().split())

# arr[col] には、区間の始まり ==> 1,区間中 ==> 0,区間終わり ==> -1
# 連続した区間は結合した形で表現される

arr = [[0]*L for j in range(c)]
for i in range(n):
    s,t,col = map(int,input().split(" "))
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

#全チャンネルを同時に考えたいもす法
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1


#累積和をとれば、区間内の最大のrec数は値のmax.
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])

print(ans)


### FIXED CODE ###

L = 100005
n,c = map(int,input().split(" "))

# arr[col] には、区間の始まり ==> 1,区間中 ==> 0,区間終わり ==> -1
# 連続した区間は結合した形で表現される

arr = [[0]*L for _ in range(c)]

for i in range(n):
    s,t,col = map(int,input().split(" "))
    arr[col-1][s-1] += 1
    arr[col-1][t-1] -= 1

imos = [0]*L

#全チャンネルを同時に考えたいもす法
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1


#累積和をとれば、区間内の最大のrec数は値のmax.
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])

print(ans)
import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

A, B,C,D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))

### FIXED CODE ###

num = input()
l = [i for i in num]
count = 0
for k in range(0,len(l)-1):
    if l[k] == l[k+1]:
        count+=1
if count > 0:
    print("Bad")
else:
    print("Good")
# coding: utf-8
import sys

try:
    inputline = list(input()) #1文字ずつ文字のリストに
    akihabara = list("AKIHABARA")
    
    lineLength = len(akihabara) - len(inputline)
    # 正解より文字数が多い、あるいは文字数が5文字以下のとき
    if lineLength < 0 or lineLength >= 5:
        print("NO")
        sys.exit()
    # 正解と文字数が同じとき
    elif lineLength == 0:
        if inputline == akihabara:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()
    # 正解より文字数が少ないとき
    else:
        for i in range(9):
            if i == 8 and len(inputline)<9:
                inputline.append("A")
            elif inputline[i] != akihabara[i]:
                inputline.insert(i, "A")
    
    if inputline == akihabara:
        print("YES")
        sys.exit()
    else:
        print("NO")
        sys.exit()

except RuntimeError:
    print("NO")
    sys.exit()


### FIXED CODE ###

# coding: utf-8
import sys
 
inputline = list(input()) #1文字ずつ文字のリストに
akihabara = list("AKIHABARA")

# Aの数
count = 4

lineLength = len(akihabara) - len(inputline)
for i in range( len(inputline) ):
    if inputline[i] == "A":
      count -= 1
#print(count)
# 正解より文字数が多い、あるいは文字数が5文字以下のとき
if lineLength < 0 or len(inputline)+count < 9 :
    print("NO")
# 正解と文字数が同じとき
elif lineLength == 0:
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")
# 正解より文字数が少ないとき

else:
    for i in range(9):
        if i == 8 and len(inputline)<9:
            inputline.append("A")
        elif inputline[i] != akihabara[i]:
            inputline.insert(i, "A")
            
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
candi =int((N+1)/2*N -N)
def f(count,i):
    nex_num = (i//2) + 1
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 2:
        return count +1
    return f(count,nex_num)

def f2(count,i):
    nex_num = (i+1)//2
    count += (i%nex_num)
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 0:
        return count
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
if candi > count:
    print(candi)
else:
    print(count)

### FIXED CODE ###

N = int(input())
print((N-1)*N//2)
# A 
s = input()

for i in range(0, len(s), 2):
    if len(s) < 2:
        bool = False
        break
    elif s[i] == 'h' and s[i+1] == 'i':
        bool = True
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')

### FIXED CODE ###

# A 
s = input()

for i in range(0, len(s), 2):
    if len(s)%2 == 1:
        bool = False
        break
    elif s[i] == 'h' and s[i+1] == 'i':
        bool = True
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')
import numpy as np

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

ans = np.zeros(N + 1)
ans[N] = 1

if N - 1 not in a:
    ans[N - 1] = 1

print(ans[N])

for i in range(2, N + 1):
    if N - i not in a:
        ans[N - i] = (ans[N - i + 1] + ans[N - i + 2])
    else:
        ans[N - i] = 0
        
print(int(ans[0] % (10 ** 9 + 7)))

### FIXED CODE ###

N, M=map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10**9 + 7
step = [1]*(N+1)

for a in A:
    step[a]=0
for i in range(2, N+1):
    step[i]=(step[i-1]+step[i-2])%mod*step[i]
print(step[-1])
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 20:12:17 2019

@author: Owner
"""

import numpy as np
from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
c = np.zeros(N)
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(0)))

a = [0]*M
b = [0]*M
for m in range(M):
    a[m], b[m] = ab[m]
b.sort()
res = 0
n = -1
while True:
    tmp = bisect.bisect_left(a, n)
    
    n = b[bisect.bisect_right(b, a[tmp])]
    res+=1
    if n > a[m]:
        break
    
    
        

print(res)



### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun May 19 20:12:17 2019

@author: Owner
"""

from operator import itemgetter
import bisect

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


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))

#print(ab)
x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] < x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)
n = int(input())
m = int(n / 2)

divs = []

for i in range(m):
  if i == 0:
    continue
  mod = n % i
  if mod == 0:
    an = int(n/i)
    if i <= an:
      divs.append(i)
      divs.append(an)
    else:
      break

max = len(divs) -1
print(divs[max] + divs[max-1] - 2)

### FIXED CODE ###

n = int(input())

divs = []

for i in range(1, int(n**0.5)+1):
  if n % i == 0:
      divs.append(i)
      divs.append(n // i)

max = len(divs) -1
print(divs[max] + divs[max-1] - 2)
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

def helper(i, prev=None, memo={}):

    if (i,prev) in memo: return memo[(i,prev)]

    if i >= n:
        return 0

    happ1, happ2, happ3 = 0,0,0
    if prev != 'a':
        happ1 = a[i] + helper(i+1, 'a', memo)
    if prev != 'b':
        happ2 = b[i] + helper(i+1, 'b', memo)
    if prev != 'c':
        happ3 = c[i] + helper(i+1, 'c', memo)

    ret = max(happ1, happ2, happ3)
    memo[(i,prev)] = ret
    return ret

print(helper(0))

### FIXED CODE ###

n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

def bottomup(a, b, c):
    dp = [[0 for _ in range(3)] for _ in range(n)]
    
    dp[(n-1)] = [a[n-1], b[n-1], c[n-1]]

    for i in range(n-2,-1,-1):
        dp[i][0] = a[i] + max(dp[i+1][1:])
        dp[i][1] = b[i] + max(dp[i+1][0], dp[i+1][2])
        dp[i][2] = c[i] + max(dp[i+1][:2])
    
    return max(dp[0])
    
print(bottomup(a,b,c))
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h + 1)]

  result = 0
  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
            if rti[k] > result:
              result = rti[k]
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
            if rti[k][j] > result:
              result = rti[k][j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(result)

main()

### FIXED CODE ###

h, w = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * w)

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  if s[i][0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if s[i][j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j
result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)
print(sum({'+':1,'-':-1} for c in input()))

### FIXED CODE ###

print(sum({'+':1,'-':-1}[c] for c in input()))
import sys
N = int(input())
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        IXY.append([i,x,y])
ANS = []
for h in H:
    for ixy in IXY:
        flg = True
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1":
            if h[x] != str(y):
                flg = False
                break
    if flg:l.append(ANS.append(h))
ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

### FIXED CODE ###

N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
#N人それぞれが正直か不誠実かの全パターンを生成
H = []
for i in range(2**N):
    S = str(bin(i))
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(N):
    t = int(input())
    for j in range(t):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ans = 0
for h in H:
    cnt = h.count("1")
    for ixy in IXY:
        i,x,y = ixy[0],ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            cnt = 0
            break
    ans = max(ans,cnt)
print(ans)
N,A,B - map(int,input().split())

print(min(N*A,B))

### FIXED CODE ###

N,A,B = map(int,input().split())

print(min(N*A,B))
n,k = map(int,input().split())
a = list(input().split())

s = [0] * n
count = 0
for i in range(n):
    for j in range(i,n):
        if j == i:
            a[i] = int(a[i])
            s[0] = a[j]
        else:
            a[j] = int(a[j])
            s[j-i] = a[j] + s[j-i-1]

        if s[j-i] >= k:
            count += n-j
            #print(count)
            #print(s)
            break


print(count)

### FIXED CODE ###

a, x =map(int,input().split())
if a>=x :
  print(10)
  
else:
  print(0)
import sys
import numpy as np

n = int(input())

a = []
b = []

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

a = np.array(a)
b = np.array(b)

diff = b - a

li = []
for x, y, z in zip(diff, a, b):
    li.append((x, y, z))

li = sortted(reverse=True)

stack = 0
for _, a, b in li:
    stack += a
    if stack > b:
        print("No")
        sys.exit()

print("Yes")

### FIXED CODE ###

import sys

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1])

now = 0

for a, b in ab:
    now += a
    if now > b:
        print("No")
        sys.exit()

print("Yes")
A=input()
B=input()
C=input()
s="a"
while (len(a)!=0 or s!="a") and (len(b)!=0 or s!="b") and (len(c)!=0 or s!="c"):
  if s=="a":
    s=A[0]
    A=A[1:]
  elif s=="b":
    s=B[0]
    B=B[1:]
  else:
    s=C[0]
    C=C[1:]
if len(s1)==0:
    print("A")
elif len(s2)==0:
    print("B")
else:
    print("C")


### FIXED CODE ###

A=input()
B=input()
C=input()
s="a"
while (len(A)!=0 or s!="a") and (len(B)!=0 or s!="b") and (len(C)!=0 or s!="c"):
  if s=="a":
    s=A[0]
    A=A[1:]
  elif s=="b":
    s=B[0]
    B=B[1:]
  else:
    s=C[0]
    C=C[1:]
if len(A)==0 and s=="a":
    print("A")
elif len(B)==0 and s=="b":
    print("B")
else:
    print("C")
i = 1
while 1:
    x = input().int()
    if i > 10000 or x = 0 or (1 <= x <= 10000):
        break
    print('Case ' + str(i) + ': ' + x)

### FIXED CODE ###

i = 1
while 1:
    x = int(input())
    if i > 10000 or (x < 1 or 10000 < x):
        break
    print('Case ' + str(i) + ': ' + str(x))
    i += 1
while Ture:
    text = input()
    if text = '-':
        break

    count = int(input())
    for c in range(count):
        index = int(input())
        text - text[index:] + text[:index]

print(text)

### FIXED CODE ###

while True:
    text = input()
    if text == '-':
        break

    count = int(input())
    for c in range(count):
        index = int(input())
        text = text[index:] + text[:index]

    print(text)
n,m = map(int,input().split())
a = []
b = []
l = []
ans = 0
count = 0

for i in range(n):
	a_dash,b_dash = map(int,input().split())
	a.append(a_dash)
	b.append(b_dash)

c = zip(a,b)
c = sorted(c)
a,b = zip(*c)
a = list(a)
b = list(b)

for i in reversed(range(m)):
	for j in range(count,len(a)):
		count += 1
		if a[j] + i == m:
			l.append(b[j])
		else:
			break
	print(l)
	if len(l) != 0:
		ans += max(l)
		index = b.index(max(l))
		#a.pop(index)
		#b.pop(index)
		l.pop(l.index(max(l)))
	print(a)
	print(b)
	#l.clear()

print(ans)

### FIXED CODE ###

import sys
import heapq

s = sys.stdin.readlines()
n,m = map(int,s[0].split())
a = []
b = []
l = []
ans = 0
count = 0

for i in range(1,n+1):
	a_dash,b_dash = map(int,s[i].split())
	a.append(-a_dash)
	b.append(-b_dash)

c = zip(a,b)
c = sorted(c,reverse=True)
a,b = zip(*c)
a_length = len(a)

for i in reversed(range(m)):
	for j in range(count,a_length):
		if -a[j] + i == m:
			heapq.heappush(l,b[j])
			count += 1
		else:
			break
	if len(l) != 0:
		maximum = heapq.heappop(l)
		ans += maximum

print(-ans)
l = input().split()
n = int(l[0])
a = int(l[1])
ans = n ** 2 - a
print(ans)

### FIXED CODE ###

n = int(input())
a = int(input())
ans = n ** 2 - a
print(ans)
from math import floor
A,B =input().split()
A = int(input())
B = float(input())
print(floor(A*B))


### FIXED CODE ###

from math import floor
A,B = input().split()
B="".join(B.split("."))
A=int(A)
B=int(B)
print(int(A*B//100))
c=input()
d=input()
if c[0]==d[3] and c[1]==d[1] and c[2]==d[0]:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

c=input()
d=input()
if c[0]==d[2] and c[1]==d[1] and c[2]==d[0]:
  print("YES")
else:
  print("NO")
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
middles.remove(0)
middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

if n == 2:
    print(a[1] - a[0])
    exit()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
if middles.count(0):
    middles.remove(0)
if middles.count(n-1):
    middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)
b, c = list(map(int, input().split()))
if 500 * b => c :
    print("Yes")
else:
    print("No")

### FIXED CODE ###

b, c = list(map(int, input().split()))
if 500 * b >= c :
    print("Yes")
else:
    print("No")
import math

list = []
for i in range(5):
    list.append(int(input()))
sum = 0
zeroList = [list[i] for i in range(len(list)) if list[i]%10 == 0]
otherList = [list[i] for i in range(len(list)) if not list[i]%10 == 0]
def func(x):
    return x % 10
otherList.sort(key=func)
for i in range(len(zeroList)):
    sum += zeroList[i]
for i in (otherList[1:]):
    sum += math.ceil(i/10)*10
sum += otherList[0]
print(sum)


### FIXED CODE ###

import math

list = []
for i in range(5):
    list.append(int(input()))
sum = 0
zeroList = [list[i] for i in range(len(list)) if list[i]%10 == 0]
otherList = [list[i] for i in range(len(list)) if not list[i]%10 == 0]
def func(x):
    return x % 10
otherList.sort(key=func)
for i in range(len(zeroList)):
    sum += zeroList[i]
for i in (otherList[1:]):
    sum += math.ceil(i/10)*10
if not len(otherList) == 0:
    sum += otherList[0]
print(sum)
N, M = [int(a) for a in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
flag = 0
if([1,0] in S):
    flag = 1
    print(-1)
else:
    NUM = 0
    LIST = [-1 for _ in range(M)]
    for s,c in S:
        s -= 1
        if(LIST[s]==-1):
            NUM += c*(10**(N-s-1))
            LIST[s] = c
        else:
            if(LIST[s]!=c):
                flag = 1
                print(-1)
                break
            else:
                continue
    if(LIST[0] == -1):
        if(N>2):
            NUM += 10**(N-1)
        else:
            NUM = 0
    if(flag==0):
        print(NUM)

### FIXED CODE ###

N, M = [int(a) for a in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
flag = 0
NUM = 0
LIST = [-1 for _ in range(N)]
for s,c in S:
    s -= 1
    if(LIST[s]==-1):
        NUM += c*(10**(N-s-1))
        LIST[s] = c
    else:
        if(LIST[s]!=c):
            flag = 1
            print(-1)
            break
        else:
            continue
if(LIST[0] == -1):
    if(N>1):
        NUM += 10**(N-1)
    else:
        NUM = 0
elif(LIST[0] == 0):
    if(N>1):
        print(-1)
        flag = 1
    else:
        NUM = 0
if(flag==0):
    print(NUM)
x = int(input())
a = 1
for i in x:
            if i == 0:
                      break
            print("Case { }: { }".format(a,i))
            a += 1

### FIXED CODE ###

import sys
a = 1

for i in sys.stdin:
        x = i.strip()
        if x == "0":
                break;
        print("Case {0}: {1}".format(a,x))
        a += 1
n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>0:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
print(alice-bob)

### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>1:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
if len(s_a_list) != 0:
  alice += s_a_list.pop(-1)
print(alice-bob)