peterverebics/CodeNet_Python_118 huggingface dataset:
N,M = map(int,input().split())

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

ans = 1000
for i in range(1000):
  num = str(i)
  if(len(num) == N):
    judge = 1
    for j in range(len(Num)):
      s,c = Num[j][0], Num[j][1]
      judge = judge*(num[s] == str(c))
    if(judge == 1):
      ans = min(ans,int(num))        
      break

if(ans == 1000): ans = -1
print(ans)
f=lambda:map(int,input().split())
n,m=f()
l=[0]*n
b=[0]*n
if n>1: l[0]=1
for _ in range(m):
  s,c=f()
  s-=1
  if b[s] and l[s]!=c or n>1 and s==c==0:
    print(-1)
    exit()
  l[s]=c
  b[s]=1
print(*l,sep='')
n, m = list(map(int, input().split()))
s = [0] * m
c = [0] * m
for i in range(m):
  s[i], c[i] = list(map(int, input().split()))
if n == 1:
  L = range(10)
if n == 2:
  L = range(10, 100)
if n == 3:
  L = range(100, 1000)
for i in L:
  I = str(i)
  flag = True
  for j in range(m):
    if int(I[s[j]-1]) != c[j]:
      flag= False
  if flag:
    print(i)
    exit()  
print(-1)
n, m = map(int, input().split())

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


for i in range(1000):
    i = str(i)
    x = 0
    if len(i) == n:
        for s, c in sc:
            if i[s-1] != str(c):
                x = 1
                break
        if x == 0:
            print(i)
            exit()

print(-1)
n, m = map(int, input().split())
dic = {}
flag = True
for _ in range(m):
  digit, num = map(int, input().split())
  if dic.get(digit, None):
    if dic[digit] != num:
      flag = False
      break
  if digit == 1 and num == 0 and n != 1:
    flag = False
    break
  if not dic.get(digit, None):
    dic[digit] = num
if flag:
  lst = [0] * n
  for digit, num in dic.items():
    lst[digit - 1] = num
  s = ''
  if lst[0] == 0 and n != 1:
    lst[0] = 1
  for ele in lst:
    s += str(ele)
  print(int(s))
else:
  print(-1)
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 and n != 1:
		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 and n == 1:
			print(0, end ="")
		elif num == 10 and i == 0:
			print(1, end = "")
		elif num == 10:
			print(0, end="")
		else:
			print(num, end ="")
	print()
N, M = map(int, input().split())

begin = 0 if N == 1 else 10**(N-1)
end = 10**N

result = [set() for _ in range(M)]
ans_set = set(range(begin, end))
for m in range(M):
    s, c = map(int, input().split())
    for n in range(begin, end):
        n_str = "0" + str(n)
        if n_str[s] == str(c):
            result[m].add(n)
    ans_set &= result[m]

ans_list = sorted(list(ans_set))
if len(ans_list) == 0:
    print(-1)
else:
    print(ans_list[0])
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    num = str(i)
    if len(num) == n and all(num[s-1]==str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)
n,m=map(int,input().split())
sc=[]
for i in range(m):
    sc.append(list(map(int,input().split())))

mm=10**(n-1)
if n==1:mm-=1
mmm=10**n
for i in range(mm,mmm):
    ok=True
    ii=str(i)
    for j in sc:
        ss=j[0]-1
        cc=j[1]

        if ii[ss]==str(cc):
            pass
        else:
            ok=False
            break
    if ok:
        print(i)
        quit()
print(-1)
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]
for i in range(10**N):
    ans=str(i)
    if len(ans)==N and all(ans[s-1]==str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)
N, M = map(int, input().split())
num = [None]*N
res = 0
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if N > 1 and s == 0 and c == 0:
        res = -1
        break    
    if num[s] == None:
        num[s] = c
    elif num[s] != c:
        res = -1
        break

print(res) if res == -1 else print(*[e if e!=None else 0 if i != 0 or N == 1 else 1 for i, e in enumerate(num)], sep="")
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

for ans in range(10 ** n):
    flag = True
    ans = str(ans)
    if len(ans) == n:
        for i in range(m):
            if str(sc[i][1]) != ans[sc[i][0] - 1]:
                flag = False
        if flag == True:
            print(ans)
            exit()
print(-1)
N, M=map(int,input().split())
nums=[list(map(int,input().split())) for i in range(M)]

for i in range(1000):
    n=str(i)
    if len(n)!=N:
        continue
    if all([n[s-1]==str(c) for s,c in nums]):
        print(n)
        break
else:
    print(-1)
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, s = map(int, input().split())
    s = str(s)
    if n == 1 and (a==1 and s=="0"):
        l[0] = s
    elif (l[a-1] and l[a-1] != s) or (a==1 and s=="0"):
        l = [-1]
        break
    else:
        l[a-1] = s

num = "".join(map(str, l))

if num[0] == "0" and n != 1:
    print("1" + num[1:])
else:
    print(num)
def inputs(): return [int(x) for x in input().split()]
n,m = inputs()
sc = [inputs() for _ in range(m)]
a = 10**n
if m==0:
  if n!=1:
    a = 10**(n-1)
  elif n==1:
    a = 0
  print(a)
  exit()
for i in range(a):
  b = str(i)
  flag = 0
  for j in range(m):
    s1,c1 = sc[j]
    if len(b)!=n or b[s1-1]!=str(c1):
      break
    flag+=1
  if flag==m:
    print(b)
    exit()
print(-1)
n,m=map(int,input().split())
fig=[0 for _ in range(n)]
fig[0]=1
f=[0 for _ in range(n)]

if n==1 and m==0:
  print(0)
  exit()

for i in range(m):
  s,c=map(int,input().split())
  if f[s-1]==1 and fig[s-1]!=c:
    print(-1)
    exit()
  else:
    f[s-1]=1
    fig[s-1]=c
if fig[0]==0 and n>=2:
  print(-1)
  exit()
ans=0
for i in range(n):
  ans+=fig[i]*(10**(n-i-1))


print(ans)
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def check(n):
  n=str(n)
  if len(n)!=N:
    return False
  for j in range(M):
    if n[int(S[j])]!=str(C[j]):
      return False
  return True  
N,M=MI()
S=[]
C=[]
for j in range(M):
  s,c=MI()
  s-=1         
  S.append(s)
  C.append(c)
i=0
while True:
  if check(i):
    print(i)
    exit()
  i+=1
  if i>1000:
    break  
print(-1)
N, M = list(map(int, input().split()))

sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))

# print(N, M, sc)

y = -1
for i in range(1000):
    flag = True
    i_str = str(i)
    if len(i_str) != N:
        continue
    for m in range(M):
        s, c = sc[m]
        # print(s, c)
        if i_str[s - 1] != str(c):
            flag = False
    if flag == True:
        y = i
        break

print(y)
n, m = map(int, input().split())
ss = []
cc = []
num = []

for _ in range(m):
    s, c = map(int, input().split())
    ss.append(s)
    cc.append(c)

for i in range(1000):
    if len(str(i)) != n:
        continue
    cnt = 0
    for s, c in zip(ss, cc):
        if str(i)[s-1] == str(c):
            cnt += 1
    if cnt == len(ss):
        num.append(i)

if num:
    print(num[0])
else:
    print(-1)
N,M=map(int,input().split())
x=[-1]*N
for i in range(M):
    s,c=map(int,input().split())
    if x[s-1]==-1:
        x[s-1]=c
    elif x[s-1]!=c:
        print(-1)
        exit()
if N>=2:
    if x[0]==0:
        print(-1)
        exit()
    if x[0]==-1:
        x[0]=1
else:
    if x[0]==-1:
        x[0]=0
for a in range(N):
    if x[a]==-1:
        x[a]=0

print(*x,sep="")
N,M= map(int,input().split())

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

ans = [0]*N
if N != 1:
    ans[0] = 1

pre_s = []

check = {}
for s,c in sc:
    if s in check:
        if c != check[s]:
            print(-1)
            exit()
    else:
        check[s] = c
    ans[s-1] = c

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

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

print(ans)
N, M = map(int, input().split(' '))
number_list = [-1] * N
flag = True
for _ in range(M):
    s, c = map(int, input().split(' '))
    if number_list[s - 1] in [-1, c]:
        number_list[s - 1] = c
    else:
        flag = False
if number_list[0] == 0 and N > 1:
    flag = False
if flag:
    if N > 1 and number_list[0] == -1:
        number_list[0] = 1
    number_list = [x if x != -1 else 0 for x in number_list]
    print(''.join(str(x) for x in number_list))
else:
    print(-1)
N,M = map(int,input().split())
SCdash = [[int(i) for i in input().split()] for m in range(M)]
SC = [[scc[0]-1,str(scc[1])] for scc in SCdash]
SG = [(0,10),(10,100),(100,1000)]
for x in range(*SG[N-1]):
    keta = str(x)
    if all([keta[s]==c for s,c in SC]):
        print(x)
        exit()
print(-1)
N,M = map(int,input().split())
SC = []
for _ in range(M):
    sc = list(map(int,input().split()))
    SC.append(sc)
#print(SC)

for num in range(1000):
    ans = True
    #znum = str(num).zfill(3)
    znum = str(num).zfill(N)
    #print(znum)
    for sc in SC:
        if znum[sc[0]-1] != str(sc[1]):
            ans = False
    if ans:
        if len(str(num)) == N:
            print(num)
            #print(znum)
            exit()
print(-1)
n,m = map(int, input().split())

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

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

ans = ""
for i in nums:
  ans += str(i)
ans = int(ans)

if len(str(ans)) == n: print(ans)
else: print(-1)
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in [0]*M]

ans = ["*"]*N
for s,c in SC:
    if ans[s-1] == str(c) : continue
    if ans[s-1] != "*" :
        ans = ["-1"]
        break
    ans[s-1] = str(c)

if ans[0] == "0" and N!=1:
    ans = ["-1"]
if ans[0] == "*":
    if N==1:ans[0] = "0"
    else:ans[0] = "1"
for i,_ in enumerate(ans[1:],1):
    if ans[i] == "*":
        ans[i] = "0"
print("".join(ans))
n,m = map(int,input().split())
sc = [[i for i in map(int,input().split())] for j in range(m)]
start = 0
goal = 0
if n==1:
  start = 0
  goal = 9
elif n==2:
  start = 10
  goal = 99
elif n==3:
  start = 100
  goal = 999

flag = 1
ans = -1
for num in range(start,goal+1):
  flag = 1
  for i in range(m):
    if str(num)[sc[i][0]-1] != str(sc[i][1]): #両辺ともちゃんとstrで変換
      flag = 0
  if flag == 1:
    ans = num
    break
print(ans)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

for i in range(10 ** (n - 1) - (n == 1), 10 ** n):
    is_ok = True
    for s, c in sc:
        s -= 1
        if int(str(i)[s]) != c:
            is_ok = False
    if is_ok:
        print(i)
        exit()
print(-1)
n, m = map(int, input().split())
a = [-1] * n
for i in range(m):
    p, d = map(int, input().split())
    if a[p - 1] != -1 and a[p - 1] != d:
        print(-1)
        exit()
    else:
        a[p - 1] = d
if a[0] == 0 and n != 1:
    print( -1 )
    exit()
for i in range(n):
    if a[i] == -1:
        a[i] = 0
if a[0] == 0 and n != 1:
    a[0] = 1

for i in range(n):
    print(a[i], end = "")
N, M = list(map(int, input().split()))
if (N==1) and (M==0):
  print(0)
  exit()
B = {}
for i in range(M):
  k, v = input().split()
  if (k in B) and (B.get(k)!=v):
    print(-1)
    exit()
  else:
    B[k] = v
if (N!=1) and (B.get("1", "99")=="0"):
  print(-1)
  exit()
ans = B.get("1", "1")
for i in range(2, N+1):
  ans = ans + str(B.get(str(i), 0))
print(ans)
nn,m=map(int,input().split())
sc=[list(map(int,input().split()))for _ in range(m)]
def check(n):
  ss=str(n)
  if len(ss)!=nn:return False
  for s,c in sc:
    if ss[s-1]!=str(c):return False
  return True
for i in range(1000):
  if check(i):print(i);exit()
print(-1)
n,m=map(int,input().split())
o=[list(map(int,input().split()))for i in range(m)]
for i in range(10**n):
    if len(str(i))==n and all(str(i)[j-1]==str(k) for j,k in o):
        print(i)
        break
else:print(-1)
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
ans = 10 ** (N - 1) if N != 1 else 0
while ans < 10 ** N:
    for s, c in C:
        if str(ans)[s - 1] == str(c):
            continue
        else:
            break
    else:
        print(ans)
        break
    ans += 1
else:
    print(-1)
n,m = map(int,input().split())
sc = [input() for _ in range(m)]
ans = -1

for i in range(0,10**n):
    i = str(i)
    ok = 0
    
    if len(i) != n:
        continue
    
    for j in sc:
        s,c = j.split()
        
        if i[int(s)-1] == c:
            ok += 1
        
    if ok == m:
        ans = int(i)
        break
        
print(ans)
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for _ in range(M)]
if M == 0 and (N > 1):
  print(10 ** (N - 1))
  exit(0)
for x in range(10 ** N):
  f = 1
  for i in range(M):
    s = str(x)
    y, c = t[i]
    if len(s) < y or (len(s) < N):
      f = 0
      break
    if int(s[y - 1]) != c:
      f = 0
      break
  if f:
    print(x)
    exit(0)
print(-1)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    start = 0
    stop = 9
elif n == 2:
    start = 10
    stop = 99
else:
    start = 100
    stop = 999

ans = -1
for num in range(start, stop + 1):
    no_flag = False
    for i in range(m):
        if str(num)[sc[i][0]-1] != str(sc[i][1]):
            no_flag = True
    if not no_flag:
        ans = num
        break

print(ans)
N, M = map(int, input().split())
ans = -1
cond = []
for i in range(M):
  cond.append(list(map(int, input().split())))
for i in range(10**3):
  D = True
  s = str(i)
  if M == 0 and N >= 2:
    ans = 10 ** (N-1)
    break
  for j in range(M):
    if N > len(s):
      D = False
      break
    if s[cond[j][0]-1] != str(cond[j][1]):
      D = False
      break
  if D == True:
    ans = i
    break
print(ans)
# C - Guess The Number

N, M = map(int, input().split())
num = [-1] * N
ans = True

for _ in range(M):
    s, c = map(int, input().split())
    if num[s - 1] != -1 and num[s - 1] != c:
        ans = False
        break
    num[s - 1] = c

if 1 < N and num[0] == 0:
    ans = False

if 1 < N and num[0] == -1:
    num[0] = 1

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

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

print(''.join([str(n) for n in num]) if ans else -1)
N,M=map(int,input().split())

S=[]
C=[]

for i in range(M):
    s,c=map(int,input().split())
    S.append(s-1)
    C.append(c)

for n in range(1000):
    ns=str(n)
    nl=list(ns)
    if len(ns)!=N:
        continue
    f=True
    for m in range(M):
        if nl[int(S[m])]!=str(C[m]):
            f=False
            break
    if f==True:
        print(n)
        exit()
print(-1)
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for j in range(1000):
    a = str(j)
    if len(a) == n:
        ans = "y"
        for i in range(m):
            if a[sc[i][0]-1:sc[i][0]] != str(sc[i][1]):
                ans = "n"
                break
        if ans == "y":
            print(a)
            break
if j == 999 and ans == "n":
    print(-1)
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]   
ans = [0 for _ in range(n)]

flg = True
for x,y in l:
    if x == 1 and y == 0 and n > 1:
        flg = False
    elif ans[x-1] == 0 or ans[x-1] == y:
        ans[x-1] = y
    else:
        flg = False
        break


ans = [str(i) for i in ans]

if n > 1 and ans[0] == '0':ans[0] = '1'

print(''.join(ans) if flg else -1)
import sys
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

for x in range(1000):
    ii = 2
    y = str(x)
    if len(y) != n:
        continue
    
    for _ in range(m):
        s = inp[ii]; ii += 1
        c = inp[ii]; ii += 1
        if y[s - 1] != chr(c + 48):
            break
    else:
        print y
        break
    continue
else:
    print -1
#abc157c
n,m=map(int,input().split())
sc=[]
for i in range(m):
 s,c=list(map(int,input().split()))
 sc.append([s,c])
for i in range(10**n):
 st=str(i)
 if len(st)!=n:
  continue
 if all([st[s-1]==str(c) for s,c in sc]):
  print(st)
  exit()
print(-1)
from collections import defaultdict
N, M = map(int, input().split())
constraint = defaultdict(set)
for _ in range(M):
    s, c = map(int, input().split())
    constraint[s].add(c)

for k, v in constraint.items():
    if len(v) > 1:
        print(-1)
        exit()

for i in range(1001):
    i = str(i)
    if len(i) != N:
        continue
    flag = True
    for k, v in constraint.items():
        if i[k-1] != str(list(v)[0]):
            flag = False
    if flag:
        print(i)
        exit()
print(-1)
n,m = map(int,input().split())
ls =[]

for _ in range(m):
  s,c = input().split()
  s = int(s)-1
  ls.append([s,c])

ans = -1
for i in range(pow(10,n)):
  s = str(i).zfill(n)
  p = True
  for a in ls:
    if not (s[a[0]] == a[1]):
      p = False
  if p and len(str(i))==n:
    ans = i
    break
print(ans)
n,m = map(int,input().split(" "))
if n == 1:
    a,b = 0,10
if n == 2:
    a,b = 10,100
if n == 3:
    a,b = 100,1000
ar = []
for i in range(m):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for i in range(a,b):
    j = str(i)
    count = 0
    for r in ar:
        if j[r[0]-1] != str(r[1]):
            count += 1
            break
    if count == 0:
        print(j)
        exit()
print(-1)
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in range(M)]
flag = 1
for i in range(1000):
  if len(str(i)) < N:
    continue
  flag = 1
  for s,c in SC:
    c = str(c)
    if str(i)[s-1] != c:
      flag = 0
  if flag == 1:
    print(i)
    exit()

print(-1)
import numpy as np 

N, M = map(int, input().split())
condition = np.array([input().split() for i in range(M)])
condition = condition.astype(np.int64)

finish = 0

for num in range(1000):
	x = str(num)
	if len(x) != N:
		pass
	else:
		array = list(map(int, x))
		check = 0

		for i in range(len(x)):
			for j in range(M):
				if condition[j][0] == i + 1 and condition[j][1] == array[i]:
					check += 1

		if check == M:
			print(x)
			finish = 1
			break

if finish == 0:
	print(-1)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = 1000
if n == 1:
    mn = 0
else:
    mn = 10 ** (n - 1)
for num in range(mn, 10 ** n):
    st = str(num)
    bl = True
    for s, c in sc:
        s -= 1
        if st[s] != str(c):
            bl = False

    if bl:
        ans = min(ans, num)

if ans == 1000:
    ans = -1

print(ans)
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] == '*':
    if N == 1:
        ans[0] = '0'
    else:
        ans[0] = '1'

if ans[0] == '0' and N > 1:
    print(-1)
else:
    ans = ''.join(ans)
    print(ans.replace('*', '0'))
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

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

for k in range(N):
    if ans[k]==-1: ans[k]=1 if k==0 and N>1 else 0

if N>1 and ans[0]==0:
    print(-1)
    exit()
    
print(*ans, sep='')
n,m = map(int,input().split())
raw = []
for _ in range(m):
  s,c = map(int,input().split())
  s -= 1
  raw.append([s,c])
for d in range(1000):
  e = str(d)
  e = '0' * (n-len(e)) + e
  #print(e)
  for x in raw:
    s,c = x
    if e[s] != str(c):
      break
  else:
    if e[0] == '0' and n != 1:
      continue
    else:
      print(e)
      break
  continue
else:
  print(-1)
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ret = -1
for i in range(10**n+1):
    x = str(i)
    if len(x)!=n:
        continue
    flg = True
    for s,c in sc:
        if x[s-1]!=str(c):
            flg = False
    if flg:
        ret = x
        break
print(ret)
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

for i in range(1000):
    s = str(i)
    if len(s) != n: continue
    if all(s[a - 1] == str(b) for a, b in sc):
        print(i)
        exit()

print(-1)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

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

result = []
if n == 1:
    result = [0]
if n == 2:
    result = [1, 0]
if n == 3:
    result = [1, 0, 0]

for i in sc:
    if i[0] == 1 and i[1] == 0 and n > 1:
        print(-1)
        exit()

    result[i[0]-1] = i[1]

print("".join(map(str,result)))
def main():
    N, M = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(M)]
    i_from = 10**(N-1) if N > 1 else 0
    i_to = 10**N
    for i_str in map(str, range(i_from, i_to)):
        if all(len(i_str) >= s and i_str[s-1] == str(c) for s, c in sc):
            print(i_str)
            return
    print(-1)

main()
n, m = map(int, input().split())
sc = []
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    sc.append((s, c))

for nn in range(10**n):
    sn = str(nn)
    if len(sn) != n:
        continue
    for s, c in sc:
        if int(sn[s]) != c:
            break
    else:
        print(nn)
        break
else:
    print(-1)
n,m=map(int,input().split())
l=["0"]*n
l[0]="1"
l[-1]="0"
f=[0]*n
frag=0
for i in range(m):
    s,c=map(int,input().split())
    if f[s-1]==0 or l[s-1]==str(c):
        l[s-1]=str(c)
        f[s-1]=1
    else:
        frag=1
        break
if frag==1 or (l[0]=="0" and n!=1):
    print(-1)
else:
    for j in l:
        print(j,end="")
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]

for i in range(1000):
    if len(str(i)) == N:
        for j in range(M):
            if str(i)[s[j]-1] != str(c[j]):
                break
        else:
            print(i)
            break
else:
    print(-1)
N, M = list(map(int, input().split()))
suuji = [-1 for _ in range(N)]

for _ in range(M):
  s, c = list(map(int, input().split()))
  if any([suuji[s-1] not in [-1, c], s > N, all([s==1, c==0, N>1])]):
    print(-1)
    break
  else:
    suuji[s-1] = c
else:
  if suuji[0] == -1 and N > 1:
    suuji[0] = 1
  elif suuji[0] == -1 and N == 1:
    suuji[0] = 0
  for i in range(1,N):
    if suuji[i] == -1:
      suuji[i] = 0
  print(int(''.join([str(i) for i in suuji])))
import sys
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
d=[-1 for _ in range(n)]
for b in s:
  if d[b[0]-1]== -1:
    d[b[0]-1]=b[1]
  else:
    if d[b[0]-1]!=b[1]:
      print(-1)
      sys.exit()
if d[0]==-1 and n>1:
  d[0]=1
elif d[0]== -1 and n==1:
  d[0]=0
elif d[0]==0 and n>1:
  print(-1)
  sys.exit()
  
for i in range(n):
  if d[i] ==-1:
    d[i]=0
print("".join(map(str,d)))
n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]

for i in range(999):
  i=list(str(i))
  flag=True
  for s,c in SC:
    if s-1>=len(i): break
    if int(i[s-1])!=c: break
  else:
    if len(i)==n:
      print(*i,sep='')
      exit()
print(-1)
N, M = map(int, input().split())
all = list(range(10**(N-1), 10**N))
if N == 1:
  all += [0]
# print(all)
for i in range(M):
  s, c = map(int, input().split())
  _all = []
  for j in all:
    k = str(j)[s-1]
    # print(k)
    if  int(k) == c:
      _all.append(j)
  all = _all
  if len(all) == 0:
    print(-1)
    exit()

print(min(all))
n, m = map(int, input().split())
sc = []
for _ in range(m):
    sc.append(list(map(int, input().split())))

# print(sc)
for i in range(10**3):
    if len(str(i)) == n:
        cnt = 0
        for s, c in sc:
            if int(str(i)[s-1]) == c:
                cnt += 1
        if cnt == m:
            print(i)
            exit()

print(-1)