peterverebics/CodeNet_Python_118 huggingface dataset:
n, m = map(int, input().split())

s, c = [], []

for i in range(m):
    a, b = map(int, input().split())
    s.append(a - 1)
    c.append(b)

for i in range(0, 1000):
    now = str(i)
    if len(now) != n:
        continue
    is_condition = True
    for j in range(m):
        if int(now[s[j]]) != c[j]:
            is_condition = False
    if is_condition:
        print(i)
        exit()

print(-1)
N,M=map(int,input().split())
#SC=[s,c for input().split() in range(M)]
SC=[list(input().split()) for i in range(M)]
'''
SC=[]
for i in range(M):
  SC.append((input().split()))
'''
def check(x):
  x=str(x)
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[int(s)-1]!=c:
      return False
  return True
for i in range(1000):
  if check(i):
    print(i)
    exit()
print(-1)
nn, m = list(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())
sc = [list(map(int,input().split())) for _ in range(m)]

for i in range(10**n):
    i = str(i)
    flag = True
    if len(i) == n:
        for j in range(m):
            if i[sc[j][0]-1] != str(sc[j][1]):
                flag = False
        if flag:
            print(i)
            quit()

print(-1)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
# print(sc)
for i in range(10**n):
  i2=str(i)
#   print(i2)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      exit()
print(-1)
N, M = map(int, input().split())
SC = list(tuple(map(int, input().split())) for _ in range(M))

for i in range(10**N):
    if len(str(i)) == N and all(str(i)[s-1] == str(c) for s, c, in SC):
        print(i)
        break
else:
    print(-1)
N, M = map(int,input().split())
v = []
for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    v.append((x,y))

for i in range(10**N):
    s = str(i)
    if len(s) != N:
        continue
    if all(s[a] == str(b) for a,b in v):
        print(i)
        exit()
print(-1)
n,m=map(int, input().split())
sl=[]
sc=["0"]*(n+1)
for _ in range(m):
  s,c = map(int, input().split())
  if s == 1 and c == 0 and n != 1:
    print(-1)
    exit()
  if s in sl and sc[s] != c:
    print(-1)
    exit()
  sl.append(s)
  sc[s]=c
  
if n >= 2 and sc[1] == "0":
  sc[1]=1
#print(sc)
print(int(''.join(map(str, sc[1:n+1]))))
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())
num = [0 for i in range(n)]
if n != 1:
  num[0] = 1
determined = [False for i in range(n)]
possible = True
for i in range(m):
  if n != 1 and s[i] == 1 and c[i] == 0:
    possible = False
    break
  if determined[s[i]-1] and num[s[i]-1] != c[i]:
    possible = False
    break
  num[s[i]-1] = c[i]
  determined[s[i]-1] = True

if not possible:
  print(-1)
else:
  for i in range(n):
    print(num[i], end="")
  print("")
N, M = map(int, input().split())

d = [None] * N

doubled = False

for _ in range(M):
	s, c = map(int, input().strip().split())
	if d[s - 1] == None:
		d[s - 1] = c
	else:
		if d[s - 1] != c:
			doubled = True

if doubled or (N > 1 and d[0] == 0):
	print(-1)
else:
	if d[0] == None:
		if N == 1:
			d[0] = 0
		else:
			d[0] = 1
	for i in range(1, N):
		if d[i] == None:
			d[i] = 0
	print("".join(map(str, d)))
n,m = map(int,input().split())

l = [-1]*(n+1)

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

if n != 1 and l[1] == 0:
  print(-1)
  exit()
if l[1] == -1:
  l[1] = 1
for i in range(2,n+1):
  if l[i] == -1:
    l[i] = 0
ls = list(map(str,l))
if n == 1 and m == 0:
  print(0)
  exit()
print(int(''.join(ls[1:])))
N,M=map(int,input().split())
S_C=[list(int(x) for x in input().split()) for _ in range(M)]

for i in range(10**N):
    i=str(i)
    if len(i)!=N:
        continue
    if all([i[s-1]==str(c) for s,c in S_C]):
        print(i)
        exit()
print(-1)
n,m=map(int,input().split())

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

if n != 1:
  if t[0] == 0:
    print(-1)
    exit()
  if t[0] == -1:
    t[0]=1
  for i in range(1,n):
    if t[i] == -1:
      t[i] = 0
else:
  if t[0] == -1:
    t[0] = 0
print(''.join(map(str,t)))
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
if n==1:
  start=0
  goal=10
else:
  start=10**(n-1)
  goal=10**n
ans=-1
for i in range(start,goal):
  x='0'+str(i)
  ok=True
  for j in range(m):
    if x[sc[j][0]] != str(sc[j][1]):
      ok=False
  if ok:
    ans=i
    break
print(ans)
n,m=map(int, input().split())  
sc=[]
for i in range(m):
    s,c=map(int, input().split()) 
    sc.append((s,c))

ans=-1
flg=True

for i in range(1000):
    flg=True
    if len(str(i))!=n:
        continue
    stri=str(i)
    for j in range(m):
        if stri[sc[j][0]-1]!=str(sc[j][1]):
            flg=False
            break
        else:
            continue
    if flg:
        ans=i
        break

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

ans = -1
for i in range(1000):
    num = str(i)
    if len(num) != n:
        continue

    bl = True
    for s, c in sc:
        s -= 1
        if num[s] != str(c):
            bl = False

    if bl:
        ans = i
        break

print(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]):
      flag = 0
  if flag == 1:
    ans = num
    break

print(ans)
N,M=map(int,input().split())
s=[0 for i in range(M)]
c=[0 for i in range(M)]
for i in range(M):
    s[i],c[i]=map(int,input().split())
    s[i]-=1
for n in range(10**N):
    t=str(n)
    if len(t)!=N:
        continue
    flag=1
    for i in range(M):
        if t[s[i]]!=str(c[i]):
            flag=0
    if flag==1:
        print(n)
        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)
n, m = map(int, input().split())

li = [0]*n

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

if n>1 and li[0]==0:
    li[0]=1

for i in range(n):
    print(li[i], end="")
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

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

print("-1")
N, M = map(int, input().split())

l = ["a"] * N

for i in range(M):
    s, c = map(int, input().split())
    if l[s-1] == "a" or l[s-1] == c:
        l[s-1] = c
    else:
        print(-1)
        exit()

if l[0] == "a" and N != 1:
    l[0] = 1
elif l[0] == 0 and N != 1:
    print(-1)
    exit()
#elif l[0] == 0 and N == 1:


for i in range(N):
    if l[i-1] == "a":
        l[i-1] = 0

l = [str(i) for i in l]
print("".join(l))
N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
found=False
start=pow(10,N-1)
stop=pow(10,N)
if N==1:
    start=0
for i in range(start,stop):
    i_str=str(i)
    passed=True
    for j in range(M):
        if not i_str[s[j]-1]==str(c[j]):
            passed=False
            break
    if passed:
        found=True
        print(i)
        break
if not found:
    print('-1')
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

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

    for s, c in sc:
        if int(i[s-1]) != c:
            flag = False
            break
    if flag:
        print(int(i))
        exit()

print(-1)
N,M = map(int, input().split())
ans = 0
S = [""]*N
for _ in range(M):
  s, c = map(int,input().split())
  if S[s-1] == "" or S[s-1] == c:
    S[s-1] = c
  elif S[s-1] != "" and S[s-1] != c:
    print(-1)
    exit(0)
if N != 1:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print(-1)
    exit(0)
  for i in range(1,N):
    if S[i] == "":
      S[i] = 0
elif N == 1:
  if S[0] == "":
    S[0] = 0
print(''.join(map(str,S)))
N, M = map(int, input().split())
scl = [list(map(int, input().split())) for _ in range(M)]
if N != 1:
    mincand = 10**(N-1)
else:
    mincand = 0
maxcand = 10**N-1

for i in range(mincand, maxcand+1):
    if all([str(i)[s-1] == str(c) for s, c in scl]):
        print(i)
        exit()
print(-1)
def main():

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

    start = pow(10, N-1)
    if N == 1: start = 0
    
    for v in range(start, pow(10, N)):
        t = str(v)
        if all(t[s-1] == str(c) for s, c in sc):
            return v
    return -1

if __name__ == '__main__':
    print(main())
n,m = map(int,input().split())
ans = 0
sc = []
for i in range(m):
    s, c = map(int,input().split())
    sc.append([s,c])
for i in range(1000):
    flag = True
    if len(str(i)) != n:
        continue
    else:
        for j in range(len(sc)):
            if str(i)[sc[j][0]-1] != str(sc[j][1]):
                flag = False
    if flag:
        print(i)
        exit()
print(-1)
N, M = map(int, input().split())
res = ["*"]*N
flag = True
for i in range(M):
    s, c = input().split()
    if s == "1" and c == "0":
        if N != 1:
            flag = False
    if res[int(s)-1] != "*" and res[int(s)-1] != c:
        flag = False
    res[int(s)-1] = c

if flag:
    if res[0] == "*":
        if N != 1:
            res[0] = "1"
    print("".join(x if x != "*" else "0" for x in res))
else:
    print(-1)
n, m = map(int, input().split())
a = []
for i in range(m):
	s,c = map(int, input().split())
	a.append([s,c])

for i in range(10**(n-1)-1,10**n):
	if len(str(i)) != n:
		continue
	if all(str(i)[s-1] == str(c) for s,c in a):
		print (i)
		exit()
print (-1)
N,M=map(int,input().split())
s=[];c=[]
num=[0]*N


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

for i in range(1000):
  num=str(i)
  if N != len(num):
    continue
  
  for m in range(M):
    if num[s[m]-1] != str(c[m]):
      break
  #for文のあとにelseブロックを使用
  else:
    print(num)
    exit()
    
print(-1)
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())

left = 10**(N-1)
right = 10**N
if N == 1:
    left = 0

for i in range(left,right):
    check = str(i)
    for j in range(M):
        if check[s[j]-1] != str(c[j]):
            break
    else:
        print(i)
        break
else:
    print(-1)
n,m = map(int,input().split())
ans_value = ['1'] + ['0'] * (n - 1)
check_sum = [0] * n
exist = True

for i in range(m):
	s,c = input().split()
	s = int(s)
	if not ans_value[s-1] == c:
		check_sum[s-1] += 1
	ans_value[s-1] = c
	if check_sum[s-1] >= 2:
		exist = False

if n == 1 and m == 0:
	ans = ['0']
elif n == 1 and exist:
	ans = ans_value
elif n > 1 and exist and not(ans_value[0] == '0'):
	ans = ans_value
else:
	ans = ['-1']

print(''.join(ans))
def main():
    N, M = map(int, input().split())
    sAndc = []
    for _ in range(M):
        sAndc.append(tuple(input().split()))
    for n in range(10**(N-1) if N!=1 else 10**(N-1)-1, 10**N):
        isans = True
        for (s, c) in sAndc:
            if str(n)[int(s)-1] != c:
                isans = False
        if isans:
            return n
    return -1
print(main())
n, m = map(int, input().split())
N = [0]*n
t = [0]*n
if n>1:
    N[0]=1
f = 0
for i in range(m):
    s, c = map(int, input().split())
    if t[s-1]!=0 and N[s-1]!=c:
        f = 1
    t[s-1] = 1
    N[s-1] = c

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

elif f==1:
    print(-1)

else:
    for i in range(n):
        print(N[i],end="")
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
for n in range(10**N):
    n = str(n)
    if len(n) != N:
        continue
    if all([n[SC[i][0]-1] == str(SC[i][1]) for i in range(M)]):
        print(n)
        exit()

print(-1)
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
SC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
ans = -1

def solve(num):
    if len(num) != N:
        return False
    for sc in SC:
        if int(num[sc[0]-1]) != sc[1]:
            return False
    return True
  
for i in range(10**5):
    num = str(i)
    if solve(num):
        ans = num
        break
print(ans)
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)
n,m = map(int,input().split())
ans = [0 for _ in range(n)]

z = 0
done = []
for _ in range(m):
  s,c = map(int,input().split())
  if not s in done:
    ans[s-1] = c
    done.append(s)
  else:
    if ans[s-1] != c:
      print(-1)
      z = 1
      break
      
if n != 1 and ans[0] == 0 and z ==0:
  if 1 in done:
  	print(-1)
  else:
    ans[0] = 1
    ans = map(str,ans)
    print(int(''.join(ans)))
    
else:
  ans = map(str,ans)
  if z ==0:
    print(int(''.join(ans)))
N, M = [int(i) for i in input().split()]
t = []
for i in range(M):
    t += [[int(i) for i in input().split()]]

for i in range(1000):
    s = str(i)
    if len(s) != N:
        continue
    isOK = True
    for it in t:
        if len(s) < it[0]:
            isOK = False
        else:
            isOK = isOK and (s[it[0]-1] == str(it[1]))
    if isOK:
        print(s)
        exit()
    
print(-1)
n, m = map(int, input().split())
sc_li = [list(map(int,input().split())) for _ in range(m)]
sc = []
ans = ""

for i in range(1000):
    flag = True
    ans = str(i)
    if len(ans) != n:
        continue
    for j in range(m):
        si, ci = sc_li[j]
        if int(ans[si-1]) != ci:
            flag = False
    if flag:
        print(ans)
        exit(0)

print(-1)
N, M = map(int, input().split())
start = 0
if N == 1:
    start = 0
elif N == 2:
    start = 10
else:
    start = 100
N = str(N)

sc = [list(input().split()) for _ in range(M)]

for i in range(start, 1000):
    ansF = True
    for j in range(M):
        if str(i)[int(sc[j][0]) - 1] != sc[j][1]:
            ansF = False
            break
    if ansF:
        print(i)
        exit()

print(-1)
N,M = map(int,input().split())
A = [-1]*N
for _ in range(M):
    s,c = map(int,input().split())
    if A[s-1] !=-1 and A[s-1] != c:
        print(-1)
        exit()
    A[s - 1] = c
if N>1 and A[0] == 0:
    print(-1)
    exit()
ans = 0
if N>1 and A[0] == -1:
    A[0] = 1
for a in A:
    if a == -1:
        a = 0
    ans+=a
    ans*=10
print(ans//10)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

for i in range(1000):
  t = str(i)
  if len(t) != n: continue
  judge = True
  for s, c in sc:
    if t[s-1] != str(c):
      judge = False
  if judge:
    print(t)
    exit(0)
print(-1)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

ans=[-1]*n
for s,c in sc:
  s-=1
  if ans[s]!=-1 and ans[s]!=c:
    print(-1)
    exit()
  ans[s]=c

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

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

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

ans=[str(i) for i in ans]
print(''.join(ans))
N,M=map(int,input().split())
A=["10"]*N
for i in range(M):
    s,c=input().split()
    s=int(s)
    s-=1
    if (A[s]!="10" and A[s]!=c) or (s==0 and c=="0" and N!=1):
        print("-1")
        exit()
    A[s]=c
for i in range(N):
    if A[i]=="10":
        if N==1:
            A[i]="0"
        elif i==0:
            A[i]="1"
        else:
            A[i]="0"
print("".join(A))
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) == N and all([(len(t) > s-1) and (int(t[s-1]) == c) for s, c in SC]):
        print(i)
        exit()
print(-1)
import sys
input = sys.stdin.readline

N,M = map(int,input().rstrip().split())
S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().rstrip().split())

for i in range(1000):
    ans = str(i)
    if len(ans) != N:
        continue
    ok = True
    for j in range(M):
        if int(ans[S[j]-1]) != C[j]:
            ok = False
    if ok:
        print(i)
        exit()

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

if ans[0]=='0' and n!=1:
  a=-1
if ans[0]=='a' and n==1:
  ans[0]='0'
for j in range(n):
  if ans[j]=='a':
    ans[j]='0'
if a==-1:
  print(a)
else:
  print(''.join(ans))
N, M = map(int, input().split(' '))

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


def check(n):
    sn = str(n)
    if len(sn) != N:
        return False
    for s, c in conditions:
        if sn[s] != c:
            return False
    else:
        return True


for n in range(1000):
    if check(n):
        print(n)
        break
else:
    print(-1)
(n,_),*z=[t.split()for t in open(0)]
n=int(n)
a=0
for i in range(1000):
  t=str(i)
  a|=n==-~a*len(t)and all(c==t[int(s)-1]for s,c in z)and-~i
print(a-1)
n, m = map(int, input().split())

l = []

for i in range(m):
  l.append(list(map(int, input().split())))

ans = -1
if n == 1:
  start = 0
else:
  start = 10 ** (n - 1)
for i in range(start, 10 ** n):
  s = str(i)
  result = True
  for x in l:
    if not s[x[0] - 1] == str(x[1]):
      result = False
      break
  if result:
    ans = i
    break

print(ans)
N, M = [int(n) for n in input().split()]

s = [None] * M
c = [None] * M

for i in range(M):
    s[i], c[i] = [int(n) for n in input().split()]

ans = -1
if N == 1:
    lb = 0
elif N == 2:
    lb = 10
else:
    lb = 100
    
for k in range(lb, 10 ** N):
    check = True
    n = str(k)
    for i in range(M):
        if n[s[i] - 1] != str(c[i]):
            check = False
            break
    if check:
        ans = k
        break

print(ans)
N, M = map(int, input().split())
num = [input().split() for y in range(M)]


def check(target):
    if not len(target) == N:
        return False
    for x, y in num:
        if not target[int(x)-1] == y:
            return False
    return True


for i in range(1000):
    if check(str(i)):
        print(i)
        exit()

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

for i in range(n):
	answer += str(number[i])
print(answer)
N, M = map(int, input().split())

X = ["x"]*N
flag = True

for i in range(M):
    s, c = map(int, input().split())
    if X[s-1] == "x":
        X[s-1] = c
    elif X[s-1] != c:
        flag = False
        break

if N > 1 and X[0] == 0:
    flag = False

if N > 1 and X[0] == "x":
    X[0] = 1

if flag:
    for i in X:
        if i == "x":
            print(0 ,end="")
        else:
            print(i ,end="")
else:
    print(-1)
N, M = map(int, input().split())
guess = [-1] * N
 
for i in range(M):
  s, c = map(int, input().split())
  s = s - 1
  if s == 0 and c == 0 and N>1:
    print(-1)
    exit()
  if guess[s] == -1:
    guess[s] = c
  elif guess[s] == c:
    continue
  else:
    print(-1)
    exit()
 
if len(guess) > 1 and guess[0] == -1:
  guess[0] = 1
for i in range(len(guess)):
  if guess[i] == -1:
    guess[i] = 0
    
res = map(str, guess)
print(''.join(res))
N,M = map(int,input().split())
ls = [-1]*N

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

if ls[0] == 0 and N > 1:
    print(-1)
    exit()
if ls[0] == -1 and N > 1:
    ls[0] = 1

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

print(ans)
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for j in range(m)]
for i in range(1000):
    if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in sc):
        print(i)
        break
else:
    print(-1)
n,m=map(int,input().split())
sc=[[0]*2 for ii in range(m)]
for ii in range(m):
  sc[ii][:]=map(int,input().split())
s=[0]*n
f=[False]*n
for ii in range(m):
  if f[sc[ii][0]-1]:
    if s[sc[ii][0]-1]!=sc[ii][1]:
      print(-1)
      exit()
  else:
    f[sc[ii][0]-1]=True
    s[sc[ii][0]-1]=sc[ii][1]
    
if n>1 and s[0]==0:
  if not f[0]:
    s[0]=1
  else:
    print(-1)
    exit()
print(int("".join([str(ii) for ii in s])))
import sys

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

num = ['-'] * n

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

if n > 1:
  if num[0] == 0:
    print('-1')
    sys.exit()
  elif num[0] == '-':
    num[0] = 1 
  
for i in range(n):
  if num[i] == '-':
    num[i] = '0'
  else:
    num[i] = str(num[i])

print(''.join(num))
N, M = map(int,input().split())
sc = []
for _ in range(M):
    s, c = input().split()
    s = int(s)
    if s > N:
        print('-1')
        exit()
    sc.append([s, c])
 
ans = -1
if N == 1:
    start = 0
else:
    start = 10 ** (N - 1)
for i in range(start, 10 ** N):
    str_num = str(i)
    for s, c in sc:
        if str_num[s - 1] != c:
            break
    else:
        ans = i
        break
print(ans)
N, M = map(int, input().split())
arr = [10] * N
for _ in range(M):
  idx, num = map(int, input().split())
  if arr[idx - 1] == 10:
    arr[idx - 1] = num
  else:
    if arr[idx - 1 ] != num:
      print(-1)
      exit()

if arr[0] == 0:
  if N == 1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
elif arr[0] == 10:
  if N == 1:
    print(0)
    exit()
  else:
    arr[0] = 1
  
for i in range(N):
  if arr[i] == 10:
    arr[i] = 0

for i in arr:
  print(i,end="")
N, M = map(int, input().split())
A = [str(i) for i in range(1 * 10 ** (N - 1), 1 * 10 ** N)]
if N == 1:
  A.append('0')
for i in range(M):
  t = list(map(int, input().split()))
  A = [A[j] for j in range(len(A)) if int(A[j][t[0] - 1]) == t[1]]
print(-1 if (not A) == True else min(A))
# ABC157C - Guess The Number
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for m in range(M)]
for i in range(10**N):
    if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)
N, M = map(int, input().split())

d = {}
flag = True

for i in range(M):
    s, c = map(int, input().split())
    if s in d.keys() and d[s] != c:
        flag = False
    d[s] = c

if M == 0:
    if N > 1: d[1] = 1
    else: d[1] = 0
elif 1 not in d.keys():
    d[1] = 1
elif N > 1 and d[1] == 0:
    flag = False

if M != 0 and max(d.keys()) > N:
    flag = False

if flag:
    res = 0
    for s, c in d.items():
        res += c * 10 ** (N - s)
    print(res)
else:
    print("-1")