peterverebics/CodeNet_Python_118 huggingface dataset:
N,M = map(int,input().split())
array = [ list(map(int,input().split())) for _ in range(M) ]
ans = [10]*N
count = 0
for i in range(M):
  if ans[ array[i][0] - 1 ] != array[i][1]:
    count += 1
  ans[ array[i][0] - 1 ] = array[i][1]
if count > N:
  print(-1)
elif ans[0] == 10 and len(ans) > 1:
  print(-1)
else:
  for i in  range(N):
    if ans[i] == 10:
      ans[i] = 0
  ans = map(str,ans)
  answer = ''.join(ans)
  print(int(answer))
N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    si, ci = map(int, input().split())
    s.append(si-1)
    c.append(ci)

answer = [0] * N
valid = True
for i in range(M):
    if answer[s[i]] != 0 and answer[s[i]] != c[i]:
        valid = False
        break
    answer[s[i]] = c[i]

if answer[0] == 0 and N != 1:
    valid = False
if valid:
    print(int(''.join(map(lambda x: str(x), answer))))
else:
    print(-1)
n,m=map(int,input().split())
s,c=[],[]

for _ in range(m):
    a,b=[int(i) for i in input().split()]
    a-=1
    s.append(a)
    c.append(b)
        
for i in range(10**(n-1),10**n):

    f=True    
    for j in range(m):
       if str(i)[s[j]] != str(c[j]):
            f=False
          
    if f==True:
        print(i)
        exit()

print(-1)
N, M = [int(i) for i in input().split()]
s_c = [[int(i) for i in input().split()] for _ in range(M)]
s_c = list(map(list, set(map(tuple, s_c))))

number = {}
for i in s_c:
  if i[0] in number:
    print(-1)
    exit()
  number[i[0]] = i[1]

ans = 0
for i in range(1, N+1):
  if N+1-i in number:
    ans+=number[N+1-i]*(10**(i-1))

if len(str(ans)) < N:
  print(-1)
  exit()

print(ans)
N,M = map(int,input().split())
ans = [0] * N
sc = []
for i in range(M):
    s,c = map(int,input().split())
    sc.append((s,c))
sc = sorted(sc,reverse=True)
#print(sc)
for s,c in sc:
    ans[s-1] = c
if N == 3:
    if ans[0] == 0 or (ans[0] == 0 and ans[1] == 0) or (ans[0] == 0 and ans[1] == 0 and ans[2] == 0):
        print(-1)
        exit()
if N == 2:
    if ans[0] == 0:
        print(-1)
        exit()
print("".join([str(i) for i in ans]))
#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans = []
for i in range(10**(n-1),10**n):
    cnt = 0
    seq = str(i)
    for j in range(m):
        if seq[int(sc[j][0])-1] == sc[j][1]:
            cnt += 1
    if cnt == m:
        ans.append(i)
if len(ans) == 0:
    print('-1')
else:
    print(min(ans))
N, M = map(int, input().split())
# print("N:", N, "M:", M)
s = [list(map(int, input().split())) for _ in range(M)]
# print(s)

c = []
for i in range(N):
    c.append(0)

for i in s:
    if i == 0 and i[1] == 0:
        pass
    elif (c[i[0] - 1] > i[1]):
        c[i[0] - 1] = i[1]

c = map(str, c)

d = ''.join(c)
if (d[:1] == "0") and (N != 1):
    print("-1")
else:
    print(d)
n,m= map(int,input().split())
check=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if(check[s]!=-1 and check[s]!=c):
        print(-1)
        exit()
    check[s]=c
#print(check)
if(check[0]==0):
    print(-1)
    exit()
elif(check[0]==-1):
    check[0]=1

for i in range(n):
    if(check[i]==-1):
        check[i]=0
    print(check[i],end="")
N, M = list(map(int, input().split()))
sol = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if sol[s-1] != -1 and sol[s-1] != c:
        print('-1')
        exit(0)
    sol[s-1] = c
if sol[0] == 0:
    print('-1')
    exit(0)
if sol[0] == -1:
    sol[0] = 1
for i in range(N):
    if sol[i] == -1:
        sol[i] = 0
ret = 0
for v in sol:
    ret *= 10
    ret += v
print(ret)
import sys

N, M = (int(x) for x in input().split())
num=[0]*N
check=[False]*N

for i in range(M):
  s,c=(int(x) for x in input().split())
  if M==1 and s==1 and c==0:
    print(-1)
    sys.exit(0)
  if check[s-1]==False:
    num[s-1]=c
    check[s-1]=True
  elif check[s-1]==True and num[s-1]!=c:
    print(-1)
    sys.exit(0)
if num[0]==0:
  num[0]=1
print(*num,sep="")
N,M = map(int,input().split())
li =[]
for i in range(M):
    li.append(list(map(int,input().split())))
    if li[i][0]>N:
        print("-1")
        exit()
print(li)
for i in range(10**(N-1),10**N):
    inv = True
    a = str(i)
    for j in range(M):
        if  a[li[j][0]-1] != str(li[j][1]):
            inv = False
    if inv:
        print(i)
        exit()
print("-1")
N,M = map(int,input().split())

LIST=[10]*N
for i in range(M):
    s,c = map(int,input().split())
    if LIST[N-s] > c:
        LIST[N-s]=c
for i in range(N):
    if LIST[i]==10:
        LIST[i]=0

if LIST[0]==0:
    print(-1)
else:
    LIST2 = map(str, LIST) 
    print("".join(LIST2))
n,m=map(int,input().split())
l=[-1]*n
check=False
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        break
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        break
    if i==m-1:
        check=True
if check:
    for num in l:
        if num==-1:
            print(0,end='')
        else:
            print(num,end='')
    print()
else:
    print(-1)
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
l = [0]*n
for i in range(m):
    s, c = map(int, input().split())
    if c != 0 and l[s-1]<c:
        l[s-1] = c
if l[0] == 0 and n != 1:
    print(-1)
    exit()
ans = 0
tmp = 1
for i in reversed(l):
    ans += tmp*i
    tmp *= 10
print(ans)
N, M = map(int,input().split())
s = [None]*M
c = [None]*M
for i in range(M):
    s[i], c[i] = map(int,input().split())
for n in range(10**(N-1), 10**N):
    st = str(n)
    f = True
    for i in range(M):
        if st[s[i]-1] != str(c[i]):
            f = False
            break
    if f:
        print(n)
        exit(0)
print(-1)
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1:
        a[s]=c
    else:
        if a[s]!=c:
            print(-1)
            exit()
if n>=2 and a[0]==0:
    print(-1)
    exit()
ans=""
for i in range(n):
    if a[i]==-1:
        ans+="0"
    else:
        ans+=str(a[i])
print(int(ans))
N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(M)]

ans = [None] * N

for i in a:
    if ans[i[0]-1] is None:
        ans[i[0]-1] = i[1]
    elif ans[i[0]-1] != i[1]:
        print(-1)
        exit()

if ans[0] == 0:
    print(-1)
    exit()

for i, v in enumerate(ans):
    if v is None:
        ans[i] = 0

if ans[0] == 0:
    ans[0] = 1

print(''.join(list(map(str,ans))))
N, M = map(int, input().split())
res = ["?" for _ in range(N)]


for _ in range(M):
    s, c = map(int, input().split())
    if res[s - 1] == "?" or res[s - 1] == str(c):
        res[s - 1] = str(c)
    else:
        print(-1)
        exit()

for i in range(len(res)):
    if res[i] == "?":
        res[i] = "0"

print(int("".join(res)) if res[0] != "0" else -1)
import sys

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
ume = [False for _ in range(N)]
for i, j in sc:
    if not ume[i-1]:
        ume[i-1] = True
        ans[i-1] = j
    else:
        if ans[i-1] != j:
            print(-1)
            sys.exit()

if not ume[0]:
    ans[0] = 1
elif ans[0] == 0 and N != 1:
    print(-1)
    sys.exit()

for i in ans:
    print(i, end="")
N, M = map(int, input().split())
v = [0, 0, 0]

for i in range(M):
    s, c = map(int, input().split())
    v[s - 1] = c

s = ''.join(map(str, v))
n = int(s)

if len(str(n)) == N:
    print(n)
else:
    print(-1)
# https://atcoder.jp/contests/abc157/tasks/abc157_c

N, M = map(int, input().split())
c = [-1 for _ in range(N)]

for _ in range(M):
    S, C = map(int, input().split())
    if c[S - 1] != -1 and c[S - 1] != C:
        print(-1)
        exit(0)
    c[S - 1] = C

if c[0] == 0:
    print(-1)
    exit(0)

s = ""
for i, a in enumerate(c):
    if i == 0:
        s += str(max(a, 1))
    else:
        s += str(max(a, 0))

print(s)
N,M=map(int,input().split())
ans=0
digit=[-1]*N
for i in  range(M):
    s,c=map(int,input().split())
    if digit[s-1]>=0 and digit[s-1]!=c:
        ans=-1
        break
    if s==1 and c==0 and N!=1:
        ans=-1
        break
    else:
        digit[s-1]=c

if ans!=-1:
    ans+=max(1,digit[0])*(10**(N-1))
    for j in range(1,N):
        if digit[j]!=-1:
            ans+=digit[j]*(10**(N-j-1))


print(ans)
def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return

    digits = [d.pop() if d else 0 for d in dcon]

    if sum(digits) == 0 and n != 1:
        print(-1)
    else:
        print(''.join(map(str, digits)))


main()
n,m = map(int,input().split())
x = [tuple(map(int,input().split())) for i in range(m)]
l = [0]*n
for t in x:
    l[t[0]-1]=t[1]
if l[0]==0 and not l==0:
    print(-1)
else:
    print("".join([str(i) for i in l]))
n,m = map(int,input().split())
lst = [-1 for _ in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    if lst[s-1] != -1:
        if lst[s-1] != c:
            print(-1)
            exit()
    else:
        lst[s-1] = c
if lst[0] == 0 and n != 1:
    print(-1)
    exit()
if lst[0] == -1:
    lst[0] = 1
for i in range(n):
    if lst[i] == -1:
        lst[i] = 0
    lst[i] = str(lst[i])
print("".join(lst))
n, m = map(int, input().split())
a = [0]*n
for i in range(m):
  s, c = map(int, input().split())
  if a[s-1] == 0:
    a[s-1] = c
  else:
    if a[s-1] == c:
      continue
    else:
      print(-1)
      exit()
  
if a[0] == 0:
  print(-1)
  exit()
  
b = [str(x) for x in a]
print(''.join(b))
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
for i in range(1,m):
  for j in range(i+1,m+1):
    if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:
      print(-1)
      exit()
 
for t in range(1,m+1):
  if n>=2 and sc[t-1]==[1,0]:
    print(-1)
    exit()
 
ans=[0]*n
for t in range(1,m+1):
  if ans[sc[t-1][0]-1]==0:
    ans[sc[t-1][0]-1]+=sc[t-1][1]

print(*ans,sep='')
N, M = map(int, input().split())
test_num_min = 1*(10**N)//10
test_num_max = 1*(10**N)

test_arr = []
for i in range(test_num_min, test_num_max): test_arr.append(i)

suffix = 0
for i in range(M):
    s, c = map(int, input().split())
    
    for j in range(len(test_arr)):
        if str(test_arr[suffix])[s-1] != str(c):
            del test_arr[suffix]
        else:
            suffix += 1
    suffix = 0
    

if len(test_arr) > 0: print(test_arr[0])
else: print(-1)
import sys

n,m=map(int,input().split())
sc={}
ans=""
for i in range(m):
    s,c=map(int,input().split())
    if s in sc:
        if c<sc[s]:
            sc[s]=c
    else:
        sc[s]=c
for i in range(n):
    if i+1 in sc:
        ans+=str(sc[i+1])
    else:
        ans+="0"

ans=int(ans)
if ans==0 or len(str(ans))!=n:
    ans = -1
print(ans)
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]
kouho=[]
count = 0
for i in range(10**(N-1),10**N+1):
    count=0
    if len(str(i))==N:
        for j in range(M):
            if str(i)[SC[j][0]-1]==str(SC[j][1]):
                count+=1
            if count==M:
                print(i)
                exit()
else:
    print("-1")
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
print(N)
if N[0]=="a":N="1"+N[1:]
N=N.replace("a","0")
print(int(N))
# input
N, M = map(int, input().split())

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

if (1, 0) in c:
    print(-1)
else:
    ans = -1

    # check
    for i in range(1, 1000, 1):
        str_i = str(i)

        if N < len(str_i):
            break

        if N == len(str_i) and False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
            ans = i
            break

    print(ans)
N,M=map(int,input().split())
flag = True
res = ""
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = ["10"]*N
for i in range(M):
  if resList[List[i][0]-1] == "10":
    resList[List[i][0]-1] = str(List[i][1])
  else:
    if resList[List[i][0]-1] != str(List[i][1]):
      flag = False
if resList[0] == 0:
  flag = False
if flag:
  for i in range(N):
    if resList[i] == "10":
      res += "1"
    else:
      res += resList[i]
  print(int(res))
else:
  print(-1)
n,m = map(int,input().split())
s = []
c = []
ans = [0]*n
for _ in range(m):
  st,ct = map(int,input().split())
  s.append(st)
  c.append(ct)

f = 1
for i in range(m):
  if s[i] == 1 and c[i] == 0:
    f = 0
    break
  if ans[s[i]-1] != 0 and ans[s[i]-1] != c[i]:
    f = 0
    break
  ans[s[i]-1] = c[i]
if f == 0 or ans[0] == 0:
  print(-1)
else:
  print(''.join(map(str,ans)))
n, m = map(int, input().split())
lst = []
for _ in range(m):
    s, c = map(int, input().split())
    lst.append([s-1,c])
    
ans = []
for _ in range(10**(n)):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,[])
    for s in lst:
        if nums[s[0]] != str(s[1]):  
            i = 0
            break
    if i == 1:
        ans.append(_)
print(ans)
if ans:
    print(min(ans))
else:
    print(-1)
n, m = map(int, input().split())

if n == 1 and m == 0:
  print(0)
  exit()
  
ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != ' ' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)


if ans[0] == ' ':
  ans[0] = '1'
ans = ''.join(ans)

print(int(ans.replace(' ', '0')))
n, m = map(int, input().split())
a = [-1]*n
for i in range(m):
    s, c = map(int, input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] != c:
        print(-1)
        exit()
    if s == 1 and c == 0:
        print(-1)
        exit()
for i in range(n):
    if a[i] == -1:
        a[i] = 0
if n != 1 and a[0] == 0:
    a[0] = 1
for i in range(n):
    print(a[i], end="")
from collections import defaultdict
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
dc = defaultdict(int)
for i,j in a:
  if dc[i] and dc[i] != j:
    print(-1)
    exit()
  dc[i] = j
if dc[1] == 0:
  print(-1)
  exit()
ans = 0
for i,x in dc.items():
  ans += x*10**(3-i)
print(ans)
N, M = map(int, input().split())
from collections import defaultdict
dd=defaultdict(int)
dd_count=defaultdict(int)

for _ in range(M):
	s, c = map(int, input().split())
	#異なるものが2個ある
	if dd_count[s-1]>=1 and dd[s-1]!=c:
		exit(print(-1))
	else:
		dd[s-1]=c
		dd_count[s-1]+=1


ans=""
for i in range(N):
	ans+=str(dd[i])
ans=int(ans)
print(ans if ans//10*(N-1)!=0 else -1)
N, M = map(int, input().split())
# print("N:", N, "M:", M)
s = [list(map(int, input().split())) for _ in range(M)]
s.sort()
# print(s)

c = []
for i in range(N):
    c.append(0)
flg = True
for i in s:
    if i[0] - 1 == 0 and i[1] == 0 and N != 1:
        flg = False
    if (c[i[0] - 1] != 0) and c[i[0] - 1] != i[1]:
        flg = False
    c[i[0] - 1] = i[1]

c = map(str, c)
d = ''.join(c)

if (d[:1] == "0") and (N != 1):
    print("-1")
else:
    print(d)
N, M = map(int, input().split())

ans = [-1] * N

for _ in range(M):
    s, i = map(int, input().split())
    s -= 1
    if ans[s] != -1 and ans[s] != i:
        print(-1)
        exit()
    ans[s] = i

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0

ans = int(''.join(map(str, ans)))

if len(str(ans)) != N or ans == 0:
    print(-1)
    exit()

print(ans)
n, m = map(int, input().split())
ans = [-1 for i in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if ans[s-1] != -1 and ans[s-1] != c:
        print(-1)
        exit()
    ans[s-1] = c

for i in range(n):
    if ans[0] == -1:
        ans[0] = 1
    elif ans[i] == -1:
        ans[i] = 0

print(int("".join(map(str, ans))))
#!/usr/bin/env python3
(n, _), *m = [[*map(int, i.split())] for i in open(0)]

a = [0] * n

for s, c in m:
    if s==1 and c==0:
        print(-1)
        exit()
    elif a[s - 1] in (0, c):
        a[s - 1] = c
    else:
        print(-1)
        exit()

if a[0]==0:
    a[0]=1
a = int("".join([*map(str, a)]))
print(a)
import sys
rl = sys.stdin.readline

n, m = [int(x) for x in rl().split(' ')]

digits = [-1 for x in range(n)]
for i in range(m):
    s, c = [int(x) for x in rl().split(' ')]
    digits[s-1] = c

hasNonZero = False
for i in range(len(digits)):
    if digits[i] > 0:
        hasNonZero = True
    elif digits[i] < 0:
        if hasNonZero:
            digits[i] = 0
        else:
            digits[i] = 1

ans = 0
for d in digits:
    ans = ans*10 + d
print(ans)
n,m=map(int,input().split())

r=""
for i in range(n):
    if i == 0:r += '1'
    else : r+='0'
r = list(r)

k ={}
for _ in range(m):
    x,y = map(int,input().split())

    if x == 1 and y == 0: print('-1');exit()

    if k.get(x) and k[x] != y: print('-1');exit()
    else: k[x] = y

for i,j in k.items():
    r[i-1] = j

for i in r:print(i,end='')
list1 = input().split(" ")
n = int(list1[0])
m = int(list1[1])
ansnum=[]
for i in range(n):
	ansnum.append('0')

for i in range(m):
	list = input().split(" ")
	s = int(list[0])
	c = int(list[1])
	if s > n:
		ans = -1
		break
	if int(ansnum[s-1]) < c:
		ansnum[s-1] = str(c)
	ans = ''.join(ansnum)

if ansnum[0] == '0':
	ans = -1
print(ans)
n,m = map(int,input().split())
num = [0]*n
flag = 1
for i in range(m):
    s,c = map(int,input().split())
    s -= 1
    if (num[s] != 0 and num[s] != c) or (s == 0 and c == 0):
        print(-1)
        flag = 0
        break
    num[s] = c
if flag:
    num = ''.join([str(num) for num in num])
    print(num)
n, m = map(int, input().split())
sc = [map(int, input().split()) for _ in range(m)]

number = [-1] * n
for s, c in sc:
    if number[s - 1] < 0:
        number[s - 1] = c
    elif number[s - 1] != c:
        print(-1)
        exit()

res = 0
for i in range(n):
    if number[i] >= 0:
        res += number[i] * 10 ** (n - i - 1)

if len(str(res)) == n:
    print(res)
else:
    print(-1)
def check():
    N, M = map(int, input().split())
    keta = ['?']*N
    
    for _ in range(M):
        s, c = map(int, input().split())        
        if keta[s-1] == '?' or keta[s-1] == c:
            keta[s-1] = c
        else:
            return -1
    if keta[0] == 0:
        return -1
    
    keta = [0 if num == '?' else num for num in keta]
    
    return ''.join(map(str, keta))
print(check())
import sys
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
keta_list = [0] * n
ans = '-1'
if m > 0:
    for s, c in l:
        if keta_list[s-1] == 0:
            keta_list[s-1] = c
        elif keta_list[s-1] != 0 and c < keta_list[s-1]:
            keta_list[s-1] = c
ans = int(''.join(map(str, keta_list)))
if len(str(ans)) < n:
    ans = '-1'
print(ans)
# -*- coding:utf-8 -*-
n, m = map(int, input().strip().split())
digit = {}
for i in range(m):
    tmp_d, tmp = map(int, input().strip().split())
    if ((tmp_d == 1) and (tmp == 0)):
        print(-1)
        exit()
    elif (tmp_d in digit.keys()) and (digit[tmp_d] != tmp):
        print(-1)
        exit()
    else:
        digit[tmp_d] = tmp
ans = 0
for key in digit.keys():
    ans += digit[key]*(10**(n-key))
print(ans)
keta,num=map(int,input().split())
list=[list(map(int,input().split())) for i in range(num)]

ans = [0]*keta
for i in range(num):
  if ans[list[i][0]-1] < list[i][1]:
    ans[list[i][0]-1] = list[i][1]
if ans.count(0) == keta:
  print(0)
else:
  a = ''
  for s in ans:
    a += str(s)
  print(a)
n, m = map(int, input().split())
s_c = tuple(set(tuple(map(int, input().split())) for _ in range(m)))

ans = 0
for sc in s_c:
    if  (sc[0] == 1 and sc[1] == 0) or sc[0] > n:
        print('-1')
        exit()
    
    for s in s_c:
        if s[0] == sc[0] and s[1] != sc[1]:
            print('-1')
            exit()
    
    ans += pow(10, (n - sc[0])) * sc[1]

if ans < pow(10, n - 1):
    ans += pow(10, n - 1)
print(ans)
N,M = map(int,input().split())
array = [10]*N
T_F = True

for i in range(M):
  s,c = map(int,input().split())
  if s>N or (array[s-1] != 10 and array[s-1] !=c) or (s == 1 and c == 0):
    T_F = False
    break
  else:
    array[s-1] = c
ans = 0

if T_F:
  for i in range(N):
    if array[i] == 10:
        array[i] == 0
    ans += array[i]*(10**(N-i-1))
  if array[0]:
    print(ans)
  else:
    print(ans+10**(N-1))
else:
  print(-1)
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  query = []
  for i in range(m):
    s,c = (int(i) for i in input().split())
    query.append((s,c))
  ans = -1
  for i in range(1000):
    #search 0 to 999
    isanswer = True
    number = str(i)
    for s,c in query:
      if 10**(s-1) > int(number):
        isanswer = False
      elif number[s-1] != str(c):
        isanswer = False
    if isanswer:
      print(i)
      exit()
  print(ans)
solve()
N, M = map(int, input().split())

import sys
num = ['9' for _ in range(N)]

for _ in range(M):
    s, c = map(int, input().split())
    if s == 1  and c == 0:
        print(-1)
        sys.exit()
    # indexをゼロ始まり
    s -= 1
    if num[s] != '9':
        if num[s] != c:
            print(-1)
            sys.exit()
    else:
        num[s] = c

for i in range(N):
    if num[i] == '9':
        num[i] = 0

ans = int(''.join(map(str, num)))
print(ans)
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = [str(0)]*n
for i in s:
    if lis[int(i[0]) - 1] == "0" or lis[int(i[0]) - 1] == str(i[-1]):
        lis[int(i[0]) - 1] = str(i[-1])
    else:
        print(-1)
        exit()
lis = int("".join(lis))
if lis == 0:
    print(-1)
else:
    print(lis)
n, m = [int(i) for i in input().split()]
ans = [10 for i in range(n)]

for i in range(m):
	s, c = [int(j) for j in input().split()]
	if s == 1 and c == 0:
		print("-1")
		break
	elif ans[s-1] != 10 and c != ans[s-1]:
		print("-1")
		break
	else:
		ans[s-1] = c
else:

	for i, num in enumerate(ans):
		if num == 10 and i == 0:
			print(1, end = "")
		elif num == 10:
			print(0, end="")
		else:
			print(num, end ="")
	print()
import sys
#n,m
n,m=(int(x) for x in input().split())

keta = [99,99,99]

for i in range(m):
    s,c=(int(x) for x in input().split())
    if keta[s-1] <= 9 and keta[s-1] != c:
        print(-1)
        sys.exit()
    else:
        keta[s-1] = c

if n >= 2 and (keta[0] == 0 or keta[0] == 99):
    print(-1)
    sys.exit()

for i in range(n):
    if keta[i] == 99:
        print(0, end="")
    else:
        print(keta[i], end="")
n,m = map(int,input().split())
L = [0]*n
li = []
flag = True
for i in range(m):
    a,b = map(int,input().split())
    if a in li:
        if L[a-1] != b:
            flag = False
            break
    elif n > 1 and a == 1 and b == 0:
        flag = False
        break
    else:
        L[a-1] = b
        li.append(a)

if L[0] == 0:
    L[0] = 1
if flag:
    L = [str(x) for x in L]
    print("".join(L))
else:
    print(-1)
n,m=map(int,input().split())
keep=1
re_ans=""
ans=[0]*n


for i in range(m):
    s=list(map(int,input().split()))
    if ans[s[0]-1]==0:
        ans[s[0]-1]=s[1]
    elif ans[s[0]-1]==s[1]:
        keep*=1
    else:
        keep*=0

for i in ans:
    re_ans+=str(i)


if re_ans[0]=="0":
    keep*=0

if m==0:
    re_ans=1*10**(n-1)
    keep=1
print([-1,re_ans][keep])
N, M = map(int, input().split())
ans = ['*'] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] == '*' or ans[s - 1] == str(c):
        ans[s - 1] = str(c)
    else:
        print(-1)
        exit()

if ans[0] == '*':
    ans[0] = '1'
if ans[0] == '0':
    print(-1)
else:
    ans = ''.join(ans)
    print(ans.replace('*', '0'))
n,m=map(int,input().split())
dic={}
for i in range(m):
  s,c=map(int,input().split())
  if s not in dic:
    if s==1 and c==0:
      print('-1')
      exit()
    else:
      dic[s]=c
  elif dic[s]==c:
    continue
  else:
    print('-1')
    exit()

for i in range(1,n+1):
  if i in dic:
    print(dic[i],end='')
  else:
    print('0',end='')