Harryxun/stf_run huggingface dataset:
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

S2 = S[:-1]
for i in range((N - 1) // 2):
    if S2[i] != S2[N - i - 1]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i+1, t+1)



### FIXED CODE ###

S = input()
N = len(S)

if S[0] == "0" or S[-1] == "1":
    print(-1)
    exit()

D = {}
for i in range(N - 1):
    D[i + 1] = S[i]
for i in range(1, N):
    if D[i] != D[N - i]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i + 1, t + 1)
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  print("a")
  erase_apple = 0
elif L+N-1 >= 0:
  for i in range(N):
    if i + L == 0:
      break
else:
  erase_apple = N-1

print(erase_apple)
apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

### FIXED CODE ###

hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N+1):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))
import sys

m = [map(int, input().split()) for _ in range(3)]

for a in range(-1000, 1001):
    b_1 = m[0][0] - a
    b_2 = m[0][1] - a
    b_3 = m[0][2] - a
    if (m[1][0] - b_1 ==
        m[1][1] - b_2 ==
        m[1][2] - b_3) and \
        (m[2][0] - b_1 ==
         m[2][1] - b_2 ==
         m[2][2] - b_3):
        print('Yes')
        sys.exit()
print('No')


### FIXED CODE ###

# https://atcoder.jp/contests/abc088/tasks/abc088_c

import sys

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

for a in range(-1000, 1001):
    b_1 = m[0][0] - a
    b_2 = m[0][1] - a
    b_3 = m[0][2] - a
    if (m[1][0] - b_1 ==
        m[1][1] - b_2 ==
        m[1][2] - b_3) and \
        (m[2][0] - b_1 ==
         m[2][1] - b_2 ==
         m[2][2] - b_3):
        print('Yes')
        sys.exit()
print('No')
from collections import deque

n,u,v = map(int,input().split())
edge = [[] for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
q = deque()
step = [0 for _ in range(n+1)]
q.appendleft([v,0])
visied = set()
visied.add(v)
while len(q)>0:
    a,v = q.pop()
    for node in edge[a]:
        if node not in visied:
            step[node] = v+1
            q.appendleft([node,v+1])
            visied.add(node)           
q =[]
q.appendleft((u,0))
mx= 0
queue = set()
queue.add((u,0))
while len(q)>0:
    a, v = q.pop()
    p=0
    value =0
    for node in edge[a]:
        cur = v+1
        if cur<step[node]:
            add = (node,cur)
            if add not in queue:
                q.appendleft(add)
                queue.add(add)
                p=1
        else:
            value = max(value,step[node])
    if p ==0:
        mx = max(mx,value)
# print(step)
print(mx)


### FIXED CODE ###

from collections import deque

INF = -1

n, t, a = map(int, input().split())
t -= 1
a -= 1
g = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v = map(lambda x: int(x) - 1, input().split())
    g[u].append(v)
    g[v].append(u)

def bfs(start):
    dist = [INF] * n
    dist[start] = 0
    q = deque([start])
    while q:
        cur = q.pop()
        for to in g[cur]:
            if dist[to] == INF:
                dist[to] = 1 + dist[cur]
                q.appendleft(to)
    return dist

distT = bfs(t)
distA = bfs(a)
ret = 0
for v in range(n):
    if distT[v] < distA[v]:
        ret = max(ret, distA[v] - 1)
print(ret)
n,m=map(int,input().split())
l1 = [0]*n
l2 = [0]*n
for i in range(m):
        p,s=map(str,input().split())
        p= int(p)
        if s == 'AC':
                if l2[p-1] == 0:
                        l2[p-1] +=1
                else:
                        pass 
        else:
                if l2[p-1] == 0:
                        l1[p-1] +=1
                else:
                        pass
for i in range(n):
        if l2[i] == 0:
                l1[i] == 0:
                
print(sum(l2),sum(l1))

### FIXED CODE ###

n,m=map(int,input().split())
l1 = [0]*n
l2 = [0]*n
for i in range(m):
        p,s=map(str,input().split())
        p= int(p)
        if s == 'AC':
                l2[p-1] +=1
        else:
                if l2[p-1] == 0:
                        l1[p-1] +=1
cntac = 0
cntwa = 0
for i in range(n):
        if l2[i] != 0:
                cntac +=1
                cntwa += l1[i]

                
                
print(cntac,cntwa)
import math
import sys

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


A,B,C,D = map(int,input().split())
if C == 1 or D == 1:
    print(0)
    sys.exit(0)

E = lcm(C,D)
c = (A-1)//C + 1 if C!=1 else A
d = (A-1)//D + 1 if D!=1 else A
e = (A-1)//E + 1 if E!=1 else A
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)
            

### FIXED CODE ###

import fractions
A,B,C,D = map(int,input().split())
c = B//C - (A-1)//C
d = B//D - (A-1)//D
E = (C*D)//fractions.gcd(C,D)
e = B//E - (A-1)//E
answer = B-A+1-(c+d-e)
print(answer)
import sys

if __name__ == "__main__":
    C1 = list(map(int, (input().split(' '))))
    C2 = list(map(int, (input().split(' '))))
    C3 = list(map(int, (input().split(' '))))

    for i in range(100):
        for j in range(100):
            for k in range(100):
                col1 = C1[0] - i
                if col1 < 0:
                    break
                if (C2[0] - j) != col1:
                    break
                if (C3[0] - k) != col1:
                    break
                col2 = C1[1] - i
                if col2 < 0:
                    break
                if (C2[1] - j) != col2:
                    break
                if (C3[1] - k) != col2:
                    break
                col3 = C1[2] - i
                if col3 < 0:
                    break
                if (C2[2] - j) != col3:
                    break
                if (C3[2] - k) != col3:
                    break
                print('Yes')
                sys.exit()
    print('No')

### FIXED CODE ###

if __name__ == "__main__":
    N = int(input())
    A = int(input())
    remain = N % 500
    if remain <= A:
        print('Yes')
    else:
        print('No')
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

A_cs = A.cumsum()
A_cs = A_cs - A_cs[-1]/2
div = np.abs(A_cs).argmin()

print(abs(A[:div+1].sum - A[div+1:].sum()))

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

A_cs = A.cumsum()
A_cs = A_cs - A_cs[-1]/2
div = np.abs(A_cs).argmin()

print(abs(A[:div+1].sum() - A[div+1:].sum()))
import sys
import numpy as np
from numba import njit


@njit('i8[:](i8,i8[:],i8[:],i8,i8[:],i8[:])')
def solve(n, vvv, www, q, uuu, lll):
    weight_limit = 10 ** 5
    precalc_limit = min(1 << 9, n + 1)
    precalc = [np.zeros(weight_limit + 1, dtype=np.int64)]

    for u in range(1, precalc_limit):
        v = vvv[u]
        w = www[u]
        parent_dp = precalc[u >> 1]
        dp = parent_dp.copy()
        dp[w:] = np.maximum(parent_dp[w:], parent_dp[:-w] + v)
        precalc.append(dp)

    buf = np.zeros(q, dtype=np.int64)
    for i in range(q):
        u = uuu[i]
        l = lll[i]
        if u < precalc_limit:
            buf[i] = precalc[u][l]
            continue
        dp = {0: 0}
        while u >= precalc_limit:
            v = vvv[u]
            w = www[u]
            for cw, cv in list(dp.items()):
                nw = cw + w
                nv = cv + v
                if nw > weight_limit:
                    continue
                if nw not in dp or dp[nw] < nv:
                    dp[nw] = nv
            u >>= 1
        ans = 0
        for w, v in dp.items():
            ans = max(ans, v + precalc[u][l - w])
        buf[i] = ans

    return buf


n, *inp = map(int, sys.stdin.buffer.read().split())
vvv = np.array([0] + inp[0:n * 2:2], dtype=np.int64)
www = np.array([0] + inp[1:n * 2:2], dtype=np.int64)
q = inp[n * 2]
uuu = np.array(inp[n * 2 + 1::2], dtype=np.int64)
lll = np.array(inp[n * 2 + 2::2], dtype=np.int64)
ans = solve(n, vvv, www, q, uuu, lll)
print('\n'.join(map(str, ans)))


### FIXED CODE ###

import sys

n, *inp = map(int, sys.stdin.buffer.read().split())
vvv = [0] + inp[0:n * 2:2]
www = [0] + inp[1:n * 2:2]

weight_limit = 10 ** 5
precalc_limit = min(1 << 10, n + 1)
precalc = [[0] * (weight_limit + 1)]

for u in range(1, precalc_limit):
    v = vvv[u]
    w = www[u]
    dp = precalc[u >> 1][:]
    for x in range(weight_limit, w - 1, -1):
        nv = dp[x - w] + v
        if dp[x] < nv:
            dp[x] = nv
    precalc.append(dp)

buf = []
mp = iter(inp[n * 2 + 1:])
for u, l in zip(mp, mp):
    if u < precalc_limit:
        buf.append(precalc[u][l])
        continue
    dp_w = [0]
    dp_v = [0]
    while u >= precalc_limit:
        v = vvv[u]
        w = www[u]
        for i in range(len(dp_w)):
            nw = dp_w[i] + w
            if nw > l:
                continue
            nv = dp_v[i] + v
            dp_w.append(nw)
            dp_v.append(nv)
        u >>= 1
    ans = 0
    for w, v in zip(dp_w, dp_v):
        nv = v + precalc[u][l - w]
        if ans < nv:
            ans = nv
    buf.append(ans)

print('\n'.join(map(str, buf)))
n,p= map(int,input().split())
res=1
if n==1:
    res=p
elif n==2:
    for i in range(int(pow(p,1/2)),int(pow(p,1/2))+2):
        if x>p:
            break
        if p%x==0:
            res=i
else:
    for i in range(2,int(pow(p,1/n))+2):
        x=i**n
        if x>p:
            break
        if p%x==0:
            res=i
print(res)


### FIXED CODE ###

n,p= map(int,input().split())
for i in range(round(p**(1/n)),0,-1):
    if p%(i**n)==0:
        print(i)
        exit()
s = input()

s = s.replace('RL','A')

r_num = 0
l_num = 0

l = []
r = []
print(s)
now = "l"
for i in range(len(s)):
    if i == len(s) - 1 and s[i] == 'L':
        l.append(l_num+1)
    if s[i] == 'A':
        if s[i-1] == 'R':
            r.append(r_num)
            r_num = 0
            if now == 'r':
                l.append(0)
            now = 'r'
        elif s[i-1] == 'L':
            l.append(l_num)
            l_num = 0
            if now == 'l':
                r.append(0)
            now = 'l'
        else:
            r_num = 0
            l_num = 0
            r.append(r_num)
            l.append(l_num)
    elif s[i] == 'R':
        if s[i-1] == 'L' and i != 0:
            #print(l_num,i)
            l.append(l_num)
            #now = 'r'
        r_num += 1
        l_num = 0
        
    else:
        now = 'l'
        l_num += 1
        r_num = 0

ans = []

for i in range(len(l)):
    for j in range(r[i]):
        ans.append(0)
    if max(r[i],l[i])%2 == 0:
        ans.append(r[i]+1)
        ans.append(l[i]+1)
    else:
        ans.append(l[i]+1)
        ans.append(r[i]+1)
    
    for k in range(l[i]):
        ans.append(0)

print(*ans,sep="")
    

### FIXED CODE ###

s = input()

ans = [0] * len(s)

cnt = 0

for i in range(len(s)):
    if s[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()
#print(ans)
#exit()

s_list = list(reversed(s))
#s.reverse()

cnt = 0

for i in range(len(s_list)):
    if s_list[i] == 'L':
        s_list[i] = 'R'
    else:
        s_list[i] = 'L'

for i in range(len(s_list)):
    if s_list[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()

print(*ans)
n,k = map(int, input().split())
mod = 10**9+7
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

for i in range(1,k+1):
    if n-k+1 < i:
        print(0)
    else:
        a = cmb(n-k+1,i)
        b = cmb(k-1,i-1)
        print((a*b)%mod)

### FIXED CODE ###

n,k = map(int, input().split())
mod = 10**9+7
from scipy.misc import comb

for i in range(1,k+1):
    print((comb(n-k+1,i,exact=True)*comb(k-1,i-1,exact=True))%mod)
n = int(input())
t, a = int(input().split())
h = list(map(int, input().split()))

x = []

for i in h:
    b = t - 0.006 * j - a
    x.append(b)

print(x.index(min(x)))

### FIXED CODE ###

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

x = []

for i in h:
    b = abs(t - 0.006 * i - a)
    x.append(b)

print(x.index(min(x)) + 1)
K=int(input())
S=list(input())

if len(S) =< K:
    print(S)
elif len(S) > K:
    print(S[0:(SL-1):1],"...")


### FIXED CODE ###

K=int(input())
S=input()
s=list(S)

if len(s) <= K:
    print(S)
else:
    print(S[0:K:]+"...")
a = input()
if a.str.isupper():
  print("A")
else:
  print("a")

### FIXED CODE ###

a = input()
if a.isupper():
  print("A")
else:
  print("a")
x = list(map(int, input().split()))

for _ in range(5):
  if x[i] == 0:
    print(i + 1)

### FIXED CODE ###

x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
  print(1)

elif x2 == 0:
  print(2)

elif x3 == 0:
  print(3)
  
elif x4 == 0:
  print(4)
  
elif x5 == 0:
  print(5)
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

import sys

sys.setrecursionlimit(10**8)

count = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        L_ = L[j+1:]
        #print(L[i] + L[j], ">", L_, "?")
        key = len(L_) // 2
        #print("init key", key)
        past_key = 0
        n = 2
        while key:
            n *= 2
            if L[i] + L[j] > L_[key]:
                key += round(len(L_) / n)
            elif L[i] + L[j] <= L_[key]:
                #print(n, round(key / n))
                key -= round(len(L_) / n)
            
            if past_key == key:
                break
            else:
                past_key = key
            #print("next key", key)
            
        if L[i] + L[j] > L_[key]:
            count += key + 1
            

print(count)


### FIXED CODE ###

def fnt(arr,n): 
  
     
     
     
    count = 0
  
     
    for i in range(0,n-2): 
  
         
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
             
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
             
            if(k>j): 
                count += k - j - 1
  
    return count
 
 
n=int(input())
arr=input()
arr=arr.split()
arr=list(map(int,arr))
arr.sort()
print(fnt(arr,n))
# coding:utf-8
import math


def main():
    N = int(input())
    num = list(map(int, input().split()))
    # num.sort()
    # print(num)
    # print(num[0:0])
    gcd = 0
    for i in range(len(num)):
        temp_list = num[0:i]+num[i+1:]
        temp_gcd = temp_list[0]
        for i in temp_list:
            temp_gcd = math.gcd(temp_gcd, i)
        # temp_gcd = functools.reduce(math.gcd, temp_list)
        if temp_gcd > gcd:
            gcd = temp_gcd
    print(gcd)
    # ans = 0
    # print()


if __name__ == "__main__":
    main()


### FIXED CODE ###

# coding:utf-8
import fractions


def main():
    N = int(input())
    # N = 10 ** 5
    num = list(map(int, input().split()))
    # num = list(range(1, 10**5 + 1))
    # num.sort()
    gcd = 0
    gcd_list_front = []
    gcd_list_back = []
    gcd_list_front.append(num[0])
    gcd_list_back.append(num[-1])

    for i in range(1, N-1):
        gcd_list_front.append(fractions.gcd(gcd_list_front[i-1], num[i]))
        gcd_list_back.append(fractions.gcd(gcd_list_back[i-1], num[-i-1]))

    gcd_list_back.reverse()
    # print(gcd_list_front)
    # print(gcd_list_back)

    gcd = max(gcd_list_back[0], gcd_list_front[-1])

    for i in range(0, N-2):
        # print(gcd_list_front[i], gcd_list_back[i+1])
        temp_gcd = fractions.gcd(gcd_list_front[i], gcd_list_back[i+1])
        if temp_gcd > gcd:
            gcd = temp_gcd

    print(gcd)
    # ans = 0
    # print()


if __name__ == "__main__":
    main()
a, b, k = map(int, input().split())
l = list(range(a, b+1))
for i in range(len(list(set(l[:k] + l[-k:])))):
    print(sorted(list(set(l[:k] + l[-k:])))[i])

### FIXED CODE ###

a, b, k = map(int, input().split())
l = []
for i in range(k):
    if a+i <= b-i:
        l.append(a+i)
        l.append(b-i)

List = sorted(set(l))
for i in range(len(List)):
    print(List[i])
N,M = map(int,input().split())
SC = [list(map(int, input().split())) for i in range(M)]
l = []
first = []
second = []
third = []
for i in range(M):
  for s,c in SC:
    if s[i] == 1:
      first.append(c[i])
    elif s[i] == 2:
      second.append(c[i])
    elif s[i] == 3:
      third.append(c[i])
if first == []:
  print(-1)
elif second == []:
  second.append(0)
elif third == []:
  third.append(0)
l.append(min(first))
l.append(min(second))
l.append(min(third))
l = ''.join(str(n) for n in l)
print(l)

### FIXED CODE ###

N,M = map(int,input().split())
sc=[list(map(int,input().split()))for _ in range(M)]
ans = -1
for i in range(1000):
  s = str(i)
  if len(s) == N:
    flg = 0
    for a,b in sc:
      if int(s[a-1]) != b:
        flg = 1
    if flg == 0:
      ans = i
      break
print(ans)
k = int(input())
a, b = map(int, input().split())

if k < a:
  if k >= 2:
    if b - a >= k - 1:
      print("OK")
elif k == a or k == b:
  print("OK")
elif a < k  and k < b:
  print("OK")
print k == 1:
  print("OK")
else:
  print("NO")


### FIXED CODE ###

k = int(input())
a, b = map(int, input().split())

if b - a >= k - 1:
  print("OK")
elif  k == 1:
  print("OK")
elif b == k or a == k:
  print("OK")
elif b % k == 0 or a % k == 0:
  print("OK")
elif a < k and k < b:
  print("OK")
elif a != b and k == 2:
  print("OK")
elif b < k:
  print("NG")
elif a % k > b % k:
  print("OK")
else:
  print("NG")
if C >= A:
    if C <= B:
        print('Yes')
    else:
        print('No')
else:
    print('No')

### FIXED CODE ###

A, B, C = map(int,input().split())
if (C>=A) and (C<=B):
  print('Yes')
else:
  print('No')
N,D=map(int,input().split())
X=[]
Y=[]
count=0
for i in range(N):
    Xi,Yi=map(int,input().split())
    X.append(Xi)
    Y.append(Yi)

for ll in range(N):
    if (X**2+Y**2<=D):
        count +=1

print(count)

### FIXED CODE ###

N,D=map(int,input().split())
X=[]
Y=[]
count=0
for i in range(N):
    Xi,Yi=map(int,input().split())
    X.append(Xi)
    Y.append(Yi)

for ll in range(N):
    if (X[ll]**2+Y[ll]**2<=D**2):
        count +=1

print(count)
N = int(input())
s, t = map(str, input().split())

word = ""
for i in range(N):
    word = word + s[i]
    word = word + t[i]

input(word)

### FIXED CODE ###

N = int(input())
s, t = map(str, input().split())

word = ""
for i in range(N):
    word = word + s[i]
    word = word + t[i]

print(word)
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-float('inf')]*(N)
for i in range(N):
  for j in A:
    if i+numk[j]<=N:
      dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
  for i in range(M):
    if dp[m-numk[A[i]]]+1==dp[m] and m-numk[A[i]]>=0:
      ans.append(A[i])
      m-=numk[A[i]]
      break
ans.sort(reverse=True)
for i in range(len(ans)):
  ans[i]=str(ans[i])
a=''.join(ans)
print(a)

### FIXED CODE ###

N,M=map(int,input().split())
num={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
A=list(map(int,input().split()))
A.sort(reverse = True)
dp = [0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+num[j]<=N:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1)
ans = []
m=N
while m>0:
    for i in A:
        if m-num[i]>=0 and dp[m-num[i]]==dp[m]-1:
          m-=num[i]
          ans.append(str(i))
          break
print("".join(ans))
N = int(input())
A = int(input())
B = int(input())
C = A + B
if N == 1:
    print("Hello World")
else:
    print(C)

### FIXED CODE ###

N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(ans,reverse=True)
ans=0
for i in range(1,n):
  ans+=arr[i//2]
print(ans)

### FIXED CODE ###

import heapq

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
ans=0
q=[]
heapq.heappush(q,-arr[0])
for i in range(1,n):
  ans+=-heapq.heappop(q)
  heapq.heappush(q,-arr[i])
  heapq.heappush(q,-arr[i])
print(ans)
N, M = map(int, input().split())
s = [list(map(int, list(input().split()))) for i in range(M)]

ans = [-1] * M
for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

ans = [int(str(a).replace('-1', '0')) for a in ans]
res = ''.join((map(str, ans)))
if int(res) != 0:
    print(int(res))
else:
    print(-1)


### FIXED CODE ###

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

ans = [-1] * N

for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

if M == 0 and N != 1:
    ans[0] = 1
tmp = int(''.join((map(str, [int(str(a).replace('-1', '0')) for a in ans]))))
if N >= 2 and ans[0] == -1:
    ans[0] = 1

ans = [int(str(a).replace('-1', '0')) for a in ans]

res = ''.join((map(str, ans)))
if int(res) >= 0 and len(str(int(res))) == N:
    print(int(res))
else:
    print(-1)
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
a=[['.']*w for i in range(h)]
q=deque()
cnt=0
for i in range(h):
    for j,x in enumerate(sys.stdin.readline().strip()):
        if x=='#':
            deque.append(q,[i,j])
            a[i][j]=0

while len(q)>0:
    hh,ww=deque.popleft(q)

    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        
        if 0>nh or nh>=h or 0>nw or nw>=w or a[nh][nw]!='.':
            continue
        
        a[nh][nw]=a[hh][ww]+1
        cnt=max(cnt,a[nh][nw])

        deque.append(q,[nh,nw])

print(cnt)


### FIXED CODE ###

from collections import deque

h,w=list(map(int,input().split()))
a=[[c for c in input()] for _ in range(h)]
visit=[[0]*w for _ in range(h)]
q=deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            deque.appendleft(q,(i,j,0))
            visit[i][j]=1
ans=0
while len(q)>0:
    i,j,cnt=deque.pop(q)

    ans=max(ans,cnt)

    for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
        ni=i+di
        nj=j+dj
        if 0<=ni<h and 0<=nj<w and visit[ni][nj]==0:
            visit[ni][nj]=1
            deque.appendleft(q,(ni,nj,cnt+1))

print(ans)