peterverebics/CodeNet_Python_118 huggingface dataset:
N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(M)]

num = ["0"]*N

for i in l:
    num[i[0]-1] = str(i[1])
    
ans = "".join(num)

for i in l:
    if N!=1 and i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if ans[i[0]-1] != str(i[1]):
        print(-1)
        exit()
if N !=len(str(int((ans)))):
    if N == 3:
        ans = int(ans)+100
    if N == 2:
        ans = int(ans)+10
print(int(ans))
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]

l=10**(n-1)
if n==1:
    l=0
for i in range(l,10**n):
    flag=True
    s=str(i)
    for x,y in a:
        if s[x-1]!=str(y):
            flag=False
    if flag==True:
        print(i)
        exit()
print(-1)
N,M=map(int,input().split())
SC=[input().split() for _ in range(M)]
ans=["0"]*N
for s,c in SC:
  if ans[int(s)-1]!="0" and ans[int(s)-1]!=c:
    print(-1)
    exit()
  if N>1 and int(s)==1 and c=="0":
    print(-1)
    exit()
  ans[int(s)-1]=c
if N>1 and ans[0]=="0":
  ans[0]="1"
print("".join(ans))
n, m = map(int, input().split())
ans = "1" + "0" * (n - 1)
changed_already = [0 for _ in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if changed_already[s - 1] != 0 and ans[s - 1] != str(c):
        print(-1)
        exit()
    changed_already[s - 1] = 1
    ans = ans[:s - 1]  + str(c) + ans[s:]
if n == 1 and m == 0:
    print(0)
    exit()
if len(str(int(ans))) != n:
    print(-1)
    exit()
print(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 and not [] in nums:
        ans.append(_)

if ans:
    print(min(ans))
else:
    print(-1)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(0, 1000):
  i = str(i)
  flag = True
  if len(i) != N:
    continue
  for s, c in sc:
    #print(i, s, len(i))
    if len(list(i)) < s:
      flag = False
      break
    if i[s-1] != str(c):
      flag = False
      break
  if flag:
    print(i)
    exit()

print(-1)
N,M = map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(M)]
sc = set(sc)
 
ans = -1
begin = 10**(N-1) - (1 if N == 1 else 0)
end = 10**N
for i in range(begin,end):
    num = str(i)
    for s,c in sc:
        if int(num[s-1]) != c:
            break
    else: ans = i
    if ans != -1:
        break
 
print(ans)
n,m = map(int,input().split())
ans = ["-1"]*n
flag = False

for _ in range(m):
    s,c = input().split()
    s = int(s)-1
    if ans[s] != "-1" and ans[s] != c:
        flag = True
        break
    ans[s] = c
if n != 1 and ans[0] == "0": flag = True

if flag:
    print(-1)
    exit()

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

print("".join(ans))
# 標準入力
n,m = map(int,input().split())
s,c = [],[]
for i in range(m):
    ss,cc = map(int,input().split())
    s.append(ss)
    c.append(cc)

# コンフリクト判定
memo = [-1 for i in range(n)]
flag = 1
for ss,cc in zip(s,c):
    if memo[ss-1] in [-1, cc]: memo[ss-1] = cc
    else: flag = 0 ; break

if memo[0]==-1: memo[0] = 0 if n==1 else 1
if memo[0]==0 and n != 1: flag = 0
memo = [str(max(0,ele)) for ele in memo]

if flag: print("".join(memo))
else: print(-1)
N, M = map(int, input().split())
if N == 1:
    cand = list(map(str, range(0, 10)))
if N == 2:
    cand = list(map(str, range(10, 100)))
if N == 3:
    cand = list(map(str, range(100, 1000)))
for _ in range(M):
    s, c = map(int, input().split())
    new = []
    for x in cand:
        if s <= len(x) and x[s-1] == str(c):
            new.append(x)
    cand = new
if len(cand) == 0:
    print(-1)
else:
    print(min(map(int, cand)))
N, M = map(int, input().split())
sc = sorted(set([tuple(map(int, input().split()))
                 for i in range(M)]))
ans = 0
position = 0
for s_c_i in sc:
    if (s_c_i == (1, 0) and N > 1) or s_c_i[0] == position:
        ans = -1
        break
    position = s_c_i[0]
    ans += (10**(N-position))*s_c_i[1]
if ans != -1 and N > 1 and ans < 10**(N-1):
    ans += 10**(N-1)
print(ans)
f = lambda:map(int,input().split())
n,m = f()
ls,lc = [],[]
for i in range(m):
  s,c = f()
  ls.append(s)
  lc.append(c)
  if n>1 and s==1 and c==0:
    print(-1); exit()
la = [-1]*n
for i in range(n):
  if i+1 not in ls:
    la[i] = 0
  for j in range(m):
    if ls[j]==i+1:
      if la[i]>=0 and la[i]!=lc[j]:
        print(-1); exit()
      else:
        la[i] = lc[j]
if n>1 and la[0]==0:
  la[0]=1
print(''.join(map(str,la)))
def MI():return map(int,input().split())

n,m=MI()
sc=[]
for _ in range(m):
  s,c=MI()
  sc+=(s-1,c),
  
for i in range(0,999):
  S=str(i)
  if len(S)==n:
    if all([S[s]==str(c) for s,c in sc]):
      print(i)
      exit()
print(-1)
N,M = [int(i) for i in input().rstrip().split()]
n = 1 if N > 1 else 0
C = [list(range(n,10))] + [list(range(10)) for i in range(N-1)]

for m in range(M):
    s,c = [int(i) for i in input().rstrip().split()]
    s -= 1
    if c in C[s]:
        C[s] = [c]
    else:
        print(-1)
        exit()
    #print(C)
C = [str(min(c)) for c in C]
print("".join(C))
n,m=map(int,input().split())
A=[]
[A.append(list(map(int,input().split()))) for i in range(m)]
ans=[1] if n!=1 else [0]
[ans.append(0) for i in range(n-1)]
for i in range(m):
  for j in range(m):
    if A[i][0]==A[j][0] and A[i][1]!=A[j][1]:
      print(-1)
      exit()
if [1,0] in A and n!=1:
  print(-1)
  exit()

for i in range(m):
  ans[A[i][0]-1]=A[i][1]
print(int("".join(map(str,ans))))
n, m = map(int,input().split())

ans = [0 for i in range(n)]

for i in range(m):
    r,s = map(int,input().split())
    if n != 1 and r-1 == 0 and s == 0:
        ans = [-1]
        break
    if ans[r-1] != 0 and ans[r-1] != s:
        ans = [-1]
        break
    ans[r-1] = s
if n != 1 and ans[0] == 0:
    ans[0] = 1
sum = ""
for i in range(len(ans)):
    sum += str(ans[i])
print(sum)
n, m = map(int, input().split())
x = [-1]*n
ans = 0
count = 0
for i in range(m):
    s, c = map(int, input().split())
    if (s==1) and (c==0) and(n!=1):
        count = 1
    if x[s-1]!=-1 and x[s-1]!=c:
        count = 1
    if x[s-1] != c:
        ans += c*(10**(n-s))
    x[s-1] = c

if count==1:
    print(-1)
elif n==1 and ans==0:
    print(0)
elif ans>=10**(n-1):
    print(ans)
else:
    print(ans+10**(n-1))
n, m = map(int, input().split())
s, c = [], []
for _ in range(m):
    _s, _c = map(int, input().split())
    s.append(_s-1)
    c.append(_c)

for i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break
    if ok:
        print(i)
        quit()

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

for j in range(n):
    if num[j] == "A":
        num[j] = 0
    if n>1 and num[0] == 0:
        num[0] = 1
print(int("".join(map(str, num))))
n,m = map(int,input().split())
d = [0 for _ in range(n)]
d[0] = 1
sarr = []
if m == 0 and n == 1:
    d[0] = 0
for i in range(m):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and not n == 1:
        print(-1)
        exit()
    if s in sarr and c != d[s-1]:
        print(-1)
        exit()
    d[s-1] = c
    sarr.append(s)
    #print(sarr)
    #print(d)
ans = ''
for i in range(n):
    ans += str(d[i])
print(ans)
N, M = [int(i) for i in input().split()]
A = []
if N == 1:
    A = [str(i) for i in range(10)]
else:
    A = [str(i) for i in range(10**(N-1), 10**N)]

for i in range(M):
    s, c = [int(j) for j in input().split()]
    A = [a for a in A if a[s-1] == str(c)]
if len(A) > 0:
    print(A[0])
else:
    print(-1)
N, M = tuple(map(int, input().split(' ')))
cond2_list = {}
key_is_duplicate = False
for _ in range(M):
	s, c = tuple(map(int, input().split(' ')))
	if s in cond2_list and cond2_list[s] != c:
		key_is_duplicate = True
	cond2_list[s] = c

if key_is_duplicate:
	print('-1')
else:
	ans = '-1'
	for i in range(1000):
		keta = len(str(i))
		if keta != N:
			continue

		cond2 = True
		for s, c in cond2_list.items():
			if int(str(i)[s-1]) != c:
				cond2 = False
				continue
		if not cond2:
			continue

		ans = i
		break

	print(ans)
n,m=map(int,input().split())
ans = [None]*n
for _ in range(m):
    s,c = map(int,input().split())
    if n > 1 and s==1 and c==0:
        ans = [-1]
        break
    
    if ans[s-1] is None or ans[s-1] == c:
        ans[s-1] = c
    else:
        ans = [-1]
        break
else:
    for i in range(n):
        if ans[i] is None:
            ans[i] = 0 if i>0 or n==1 else 1
        
print("".join(map(str,ans)))
def ii():return int(input())
def mi():return map(int,input().split())


n,m=mi()
sc=[]
for _ in range(m):
  sc+=tuple(mi()),


if n==3:
  l=range(100,1000)
if n==2:
  l=range(10,100)
if n==1:
  l=range(0,10)


for i in l:
  num=str(i)
  if all([num[s-1]==str(c) for s,c in sc]):
    print(num)
    exit()


print(-1)
import sys

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

num = [[0] for i in range(n)]
s = []
if(n != 1):
  num[0][0] = 1

test = list(list(map(int, input().split())) for i in range(m))

for i in test:
  num[i[0] - 1].append(i[1])

for i in range(len(num)):
  if(len(set(num[i])) >= 3):
    print(-1)
    sys.exit()
  elif(i == 0 and min(num[i]) == 0 and n != 1):
    print(-1)
    sys.exit()
  s.append(str(max(num[i])))

print(''.join(s))
n, m = map(int, input().split())

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

for i in range(1,n):
  if ans[i]==-1:
    ans[i] = 0
  
print(*ans, sep='')
n,m = map(int,input().split())
a = [[0,10],[10,100],[100,1000]]
sc = [list(map(int,input().split())) for i in range(m)]
for i in range(a[n-1][0],a[n-1][1]):
  cnt = 0
  for j in range(m):
    s,c = sc[j][0],sc[j][1]
    l = str(i)
    if l[s-1] == str(c):
      cnt += 1
  if cnt == m:
    print(i)
    quit()
print(-1)
import sys
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i],c[i] = map(int,input().split())
 
for i in range(1000):
    flag = True
    if len(str(i)) == n:
        for j in range(m):
            if str(i)[s[j]-1] != str(c[j]):
                flag = False
 
        if flag:
            print(i)
            sys.exit()
print(-1)
N,M = map(int,input().split())

pattern = ["."] * N
for i in range(M):
  s,c = input().split()
  s = int(s)
  if pattern[s - 1] not in (".",c):
    print(-1)
    exit(0)
  pattern[s - 1] = c

import re

comp = re.compile("^" + "".join(pattern) + "$")

for i in range(1001):
  res = comp.match(str(i))
  if res:
    print(i)
    break
else:
  print(-1)
import sys
# スペース区切りの整数入力
N,M = map(int, input().split())

sc = {}
snum = '0' * N

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

for i in sc:
    snum = snum[:i-1] + str(sc[i]) + snum[i:] 

if N == len(str(int(snum))):
    print(snum)
else:
    if 1 in sc:
        print(-1)
    else:
        print("1"+snum[1:])
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    t = str(i)
    if len(t) != n: continue
    for s, c in sc:
        if str(c) != t[s-1]: break
    else:
        print(i)
        break
else: print(-1)
n,m = map(int, input().split())
cond = []
for _ in range(m):
    s,c = map(int, input().split())
    cond.append((s,c))


for i in range(0,1000):
    num_s = str(i)
    if len(num_s) != n:
        continue

    for s,c in cond:
        if len(num_s) < s or num_s[s-1] != str(c):
            break
    else:
        print(i)
        exit()

else:
    print(-1)
n, m = list(map(int, input().split()))
X = [-1] * n
flag = False
for _ in range(m):
    s, c = list(map(int, input().split()))
    i = s - 1
    if X[i] != -1 and X[i] != c:
        flag = True
    else:
        X[i] = c
if flag:
    print('-1')
else:
    if n > 1:
        if X[0] == -1:
            X[0] = 1
    if n > 1 and X[0] == 0:
        print('-1')
    else:
        print(''.join([str(max(x, 0)) for x in X]))
N,M = map(int, input().split())
 
sets = []
for i in range(M):
  s,c = input().split()
  sets.append((s,c))
 
start = 0
if N != 1:
  start = 10**(N-1)
 
for n in range(start,10**N):
  for s,c in sets:
    if str(n)[int(s)-1] == c:
      continue
    else:
      break
  else:
    print(n)
    break
else:
  print(-1)
n,m=map(int,input().split())

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

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

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

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

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

print(int(''.join(r)))
N, M = map(int, input().split())

SC = []
for _ in range(M):
    s, c = map(int, input().split())
    SC.append([s, c])

for i in range(1000):
    str_i = str(i)
    if len(str_i) != N:
        continue

    for sc in SC:
        index = sc[0]-1

        if len(str_i) != N:
            break
        if str_i[index] != str(sc[1]):
            break
    else:
        print(i)
        exit(0)
print(-1)
#157C
N, M = map(int, input().split())
S = [input().split() for _ in [0]*M]

for i in range(1000):
    if len(str(i)) != N:
        continue
    for s, c in S:
        if str(i)[int(s)-1] == c:
            continue
        else:
            break

    else:
        print(i)
        break
else:
    print(-1)
n,m=map(int,input().split())
l=[]
for i in range(m):
    s,c=map(int,input().split())
    l.append((s,c))

ans=-1
for i in range(1000):
    k=str(i)
    cnt=0
    if len(k)==n:
        for j in range(m):
            if int(k[l[j][0]-1])==l[j][1]:
                cnt+=1
        if cnt==m:
            ans=i
            break
if ans==-1:
    print(-1)
else:
    print(ans)
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

l=[]
for _ in range(M):
   s,t=map(int,input().split())
   l.append([s,t])

for i in range(10**(N-1) if N!=1 else 0,10**N):
    temp=list(str(i))
    judge=True
    for s,t in l:
        if temp[s-1]!=str(t):
            judge=False
    if judge:
        print(i)
        exit()
        
print(-1)
N, M = map(int, input().split())

ans = [-1]*N

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

if ans[0] == -1:
    if N == 1:
        ans[0] = 0
    else:
        ans[0] = 1

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

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

print(*ans, sep='')
n, m = map(int, input().split())
T = [list(map(int, input().split())) for i in range(m)]
ans = 0
start = 0

if n != 1:
    start = 10 ** (n - 1)

for i in range(start, 10 ** n):
    for j in range(m):
        ans = 0
        if (str(i))[(T[j][0] - 1)] != str(T[j][1]):
            ans = -1
            break
    if ans == 0:
        ans = i
        break

print(ans)
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
af = [0]*n
for i in range(m):
  if s[i] == 1 and c[i] == 0 and n != 1:
    f = 0
    break
  if af[s[i]-1] == 1 and ans[s[i]-1] != c[i]:
    f = 0
    break
  ans[s[i]-1] = c[i]
  af[s[i]-1] = 1
if f == 0:
  print(-1)
else:
  if ans[0] == 0 and n != 1:
    ans[0] = 1
  print(''.join(map(str,ans)))
import sys
N, M = map(int, input().split())

A = [-1] * N

for i in range(M):
  s, c = map(int, input().split())
  if A[s-1] != c and A[s-1] != -1:
    print(-1)
    sys.exit()
  else:
    A[s-1] = c
  
if N >= 2 and A[0] == 0:
  print(-1)
  sys.exit()

res = 0

for i in range(N):
  if A[i] == -1:
    if i == 0 and N >= 2:
      A[i] = 1
    else:
      A[i] = 0
  res += A[i] * 10 ** (N-i-1)

print(res)
N, M = map(int, input().split())
SC = [input().split() for _ in range(M)]
ans = ["0"] * N
for s, c in SC:
  # check duplicated s
  if ans[int(s) - 1] != "0" and ans[int(s) - 1] != c:
    print(-1)
    exit()
  # check impossible case
  if N > 1 and s == "1" and c == "0":
    print(-1)
    exit()
  ans[int(s) - 1] = c
# replace head
if ans[0] == "0" and N > 1:
  ans[0] = "1"
print("".join(ans))
from collections import defaultdict

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

d = defaultdict(list)
for s, c in SC:
    d[s].append(c)


if any(len(set(v)) > 1 for v in d.values()):
    print(-1)
elif d[1] == [0] and N > 1:
    print(-1)
elif N == 1 and M == 0:
    print(0)
else:
    ans = [0] * N
    ans[0] = 1
    for i in range(N):
        if d[i + 1]:
            ans[i] = d[i + 1].pop()
            
    print("".join(list(map(str, ans))))
N,M=map(int,input().split(' '))
l = [[] for i in range(N)]
ans = ''
for i in range(M):
    s,c=map(int,input().split(' '))
    s = s-1
    l[s].append(c)
for n,i in enumerate(l):
    if len(set(i)) >=2:
        print(-1)
        exit()
    elif N != 1 and n==0 and i==[]:
        ans += '1'
    elif i==[]:
        ans +='0'
    else:
        ans += str(i[0])
if len(str(int(ans))) == N:
    print(ans)
else:
    print(-1)
n,m=map(int,input().split())
num="a"*n
flag=False

for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if num[s]=="a" or num[s]==str(c):
        num=num[:s]+str(c)+num[s+1:]
    else:
        flag=True
if n==1 and ( m==0 or num=="0" ):
    print(0)
elif flag or num[0]=="0":
    print(-1)
else:
    if num[0]=="a":
        num="1"+num[1:]
    print(num.replace("a","0"))
n,m=map(int,input().split())
num=[-1]*n

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



if n==1 and num[0]<1:
    print(0)
    exit()

if num[0]==-1:
    num[0]=1

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

st=""
for i in range(n):
    if num[i]!=-1:
        st+=str(num[i])
    else:
        st+="0"

print(st)
u = input().split(" ")
n = int(u[0])
m = int(u[1])
l = {}
e = 0
a = []
if n == 1:
	a = ["0"]
elif n == 2:
	a = ["1","0"]
elif n == 3:
	a = ["1","0","0"]
for i in range(m):
	c = input().split(" ")
	s = int(c[0]) - 1
	if s in l:
		if l[s] != c[1]:
			e = 1
	else:
		l[s] = c[1]
		a[s] = c[1]
if e == 1:
	print(-1)
else:
	if n != 1 and a[0] == "0":
		print(-1)
	else:
		print("".join(a))
n,m=map(int,input().split())
data=[-1]*n
for i in range(m):
  s,c=map(int,input().split())
  if (s==1 and c==0) and n>=2:
    print(-1)
    exit()
  if data[s-1]==-1 or data[s-1]==c:
    data[s-1]=c
  elif data[s-1]!=-1 and data[s-1]!=c:
    print(-1)
    exit()
  
if data[0]==-1 and n!=1:
  data[0]=1
elif data[0]==-1 and n==1:
  data[0]=0
for i in range(1,n):
  if data[i]==-1:
    data[i]=0
print(*data,sep='')
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]
f = [0] * N
ans = ['0'] * N
for s, c in sc:
  if (f[s - 1] and ans[s - 1] != str(c)) or (N != 1 and s == 1 and c == 0):
    print(-1)
    exit()
  else:
    ans[s - 1] = str(c)
    f[s - 1] = 1
    
if N != 1 and ans[0] == '0':
  ans[0] = '1'
print(''.join(ans))
n, m = map( int, input().split() )
s = []
c = []
for _ in range( m ):
    s_i, c_i = map( int, input().split() )
    s.append( s_i )
    c.append( c_i )

if n == 1:
    init = 0
    limit = 10
elif n == 2:
    init = 10
    limit = 100
else:
    init = 100
    limit = 1000

for k in range( init, limit ):
    judge = 1
    for i in range( m ):
        if str( k )[ s[ i ] - 1 ] != str( c[ i ] ):
            judge = 0
    if judge == 1:
        print( k )
        exit()

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

ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if n != 1 and 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] == ' ' and n != 1:
  ans[0] = '1'
ans = ''.join(ans)

print(int(ans.replace(' ', '0')))
N, M = map(int, input().split())
ans = [None] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] in [None, c]:
        ans[s - 1] = c
    else:
        print(-1)
        quit()

ans = "".join(map(lambda pair :str(pair[1]) if pair[1] != None else "0" if pair[0] or N == 1 else "1", enumerate(ans)))
if N > 1 and ans[0] == "0":
    print(-1)
    quit()

print(ans)
a,b=map(int,input().split())
ans=-1
arr = [list(map(int,input().split())) for i in range(b)]

for i in range(1001):
  j=str(i)
  if len(j)==a and all(j[s-1]==str(t) for s,t in arr):
    ans = i
    break
print(ans)
n, m = map(int, input().split())
sl = [0]*m
cl = [0]*m
for i in range(m):
    sl[i], cl[i] = map(int, input().split())

for t in range(1000):
    target = str(t)
    if len(target) == n:
        ok = True
        for i in range(m):
            if target[sl[i]-1] != str(cl[i]):
                ok = False
        if ok:
            print(t)
            exit()
print(-1)
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
for i in range(1000):
    s = str(i)
    if len(s) != n:
        continue
    flag = True
    for j,k in li:
        if s[j-1] != str(k):
            flag = False
    if flag:
        print(s)
        exit()
print(-1)
def main():
    N, M = (int(i) for i in input().split())
    SC = [[int(i) for i in input().split()] for j in range(M)]
    for i in range(1000):
        S = str(i)
        if len(S) != N:
            continue
        for s, c in SC:
            if S[s-1] != str(c):
                break
        else:
            return print(S)
    print(-1)


if __name__ == '__main__':
    main()
N,M = [int(i) for i in input().split()]
d = {}
for i in range(M):
    s,c = [int(i) for i in input().split()]
    if d.get(s,c) != c:
        print(-1)
        break
    else:
        d[s] = c
else:
    if N==1:
        print(d.get(1,0))
    elif d.get(1,1) == 0:
        print(-1)
    else:
        l = [str(d.get(1,1))]
        l+=[str(d.get(i,0)) for i in range(2, N+1)]
        print(''.join(l))
N, M = map(int, input().split())
SC = []
for _ in range(M):
    s, c = map(int, input().split())
    SC.append((s - 1, c))

for n in range(1000):
    s = str(n)
    if len(s) == N and all(int(s[i]) == c for i, c in SC):
        print(n)
        break
else:
    print(-1)
N, M = map(int, input().split())
ans='1' + '0'*(N-1) if N>1 else '0'
chk=[False]*N

for m in range(M):
  s, c = input().split()
  s=int(s)
  if s==1 and c=='0' and N>1:
    print(-1); exit(0)
  if chk[s-1] and c!=ans[s-1]:
    print(-1); exit(0)
  chk[s-1]=True
  ans = ans[:s-1] + c + ans[s:]
  #print(chk, ans)
print(ans)
N, M = map(int, raw_input().split())
s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = map(int, raw_input().split())
  s[i] -= 1

for i in range(0 if N==1 else 10**(N-1), 10**N):
  i = str(i)
  ok = True
  for j in range(M):
    if i[s[j]]!=str(c[j]):
      ok = False
  if ok:
    print i
    exit(0)
print -1
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(10000):
    s = str(i)
    if len(s) != n:
        continue
    ok = True
    for a, b in sc:
        if s[a - 1] != str(b):
            ok = False
            break
    if ok:
        print(i)
        exit()

print(-1)