peterverebics/CodeNet_Python_118 huggingface dataset:
N,M=map(int,input().split())
S,C=[],[]
for m in range(M):
    s,c=map(int,input().split())
    S.append(s)
    C.append(c)
for i in range(10**(N-1),10**N):
    if all(str(i)[s-1]==str(c) for s,c in zip(S,C)):
        print(i)
        break
else:
    print(-1)
n, m = map(int, input().split())

ans = [0] * n
exist = []
flag = 0
for _ in range(m):
  s, c = map(int, input().split())
  if (s == 1) and (c == 0):
    flag += 1
  if (s in exist) and (ans[s-1] != c):
    flag += 1
  else:
    ans[s-1] = c
    exist.append(s)
stop = 0
while (ans[stop] == 0) and (stop+1 not in exist):
  if stop+1 not in exist:
    ans[stop] = 1
  stop += 1
  if stop == n:
    break

if (n == 1) and (ans[0] == 0):
  print(*ans)
elif flag >= 1:
  print(-1)
else:
  print(int("".join([str(i) for i in ans])))
import sys
input = sys.stdin.readline

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

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

    if not ans[s] in [c, -1]:
        print(-1)
        sys.exit()

    ans[s] = c

for i in range(N):
    if ans[i] == -1: ans[i] = 0
ans = int(''.join(map(str, ans)))

if ans == 0: ans = -1
print(ans)
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    if answer[si - 1] is not None and answer[si - 1] != ci:
        print(-1)
        exit()
    
    answer[si - 1] = ci

if answer[0] is None or answer[0] == 0:
    print(-1)
    exit()

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

answer = ''.join(map(str, answer))
print(answer)
n,m=map(int,input().split())
ans=[0]*n

for _ in range(m):
  s,c=map(int,input().split())
  ans[s-1]=c
if n>1 and ans[0]==0:
  print(-1)
  exit()
else:
  for i in ans:
    print(i,end="")
n,m=map(int,input().split())
if m==0:
  if n ==1:
    print(0)
  else:
    print(10**(n-1))
else:
  sc= [list(map(int,input().split())) for i in range(m)]
  ans = -1
  for j in range(10**n):
    k=str(j)
    s=[[0 for i in range(2)] for i in range(len(k))]
    for l in range(len(k)):
      s[l][0]=l+1
      s[l][1]=int(k[l])
      if all(elm in s for elm in sc) == 1:
        ans=j
        break
    if ans==j:
      break
  print(ans)
N, M = map(int, input().split())

ans = [0]*N
for _ in range(M):
    a, b = map(int, input().split())
    if ans[a-1] != 0 and ans[a-1] != b:
        ans[a-1] = -1
    elif ans[a-1] == 0:
        ans[a-1] = b

if -1 in ans or sum(ans) == 0:
    print('-1')
else:
    b = ''.join([str(i) for i in ans])
    if len(ans) == len(str(b)):
        print(b)
    else:
        print('-1')
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 n >1 and a[0] == 0:
  print(-1)
  
elif n == 1 and a[0] == 0:
  print(0)
  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)]

sc.sort(key=lambda x: x[0],reverse=True)
ans = ['0'] * n
now = -1
for i in sc:
    if ans[i[0]-1] != '0' and ans[i[0]-1] != str(i[1]):
        print(-1)
        quit()
    ans[i[0]-1] = str(i[1])
    now = i[0]

ans = str(int(''.join(ans)))
if len(ans) != n:
    print(-1)
else:
    print(ans)
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(10**(n-1),10**n):
    for j in range(m):
        i=str(i)
        if int(i[s[j]-1])!=c[j]:
            break
    else:
        ans=i
        break
else:
    ans=-1
print(ans)
N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    s, c = map(int, input().split())
    a[s-1] = c
if N == 1:
    print(*a, sep="") 
elif a[0] == 0:
    print("-1")
else:
    print(*a, sep="")
N,M = map(int, input().split())
Num = ["0","0","0"]
for _ in range(M):
  num = input().split()
  if int(num[0]) <= 3:
    Num[int(num[0])-1] = num[1]
number = int(''.join(Num))
result = -1
for i in range(1, 999):
  if i == number:
    result = number
    break
print(result)
n, m = [int(i) for i in input().split()]
s = [input() for i in range(m)]
a = [0] * n
for i in s:
  if int(i.split()[0])-1 < 4:
    a[0] = 0
  elif int(i.split()[1]) >= 10:
    a[int(i.split()[0])-1] = 0
  else:
    a[int(i.split()[0])-1] = int(i.split()[1])

if a[0] == 0:
  print(-1)
else:
  a = "".join(map(str,a))
  print(int(a))
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]
begin=10**(N-1)
end=10**N
if N==1:
  begin=0
for i in range(begin,end):
  i=str(i)
  for s,c in SC:
    if i[s-1]!=c:
      break
  else:
    print(i)
    exit()
print(-1)
n, m = map(int, input().split())
a = ['*']*n


for i in range(m):

  s, c = map(int, input().split())
  if a[s-1] == '*':
    a[s-1] = c
  else:
    if a[s-1] == c:
      continue
    else:
      print(-1)
      exit()
  
if n >1 and a[0] == 0:
  print(-1)
  exit()

  
b = [str(x) for x in a]
ans= ''.join(b)
print(ans.replace('*', '0'))
n, m = map(int,input().split())

ans = [-1 for i in range(n)]

pf = True
for i in range(m):
    s,c = map(int,input().split())
    if ((not ans[s-1] == -1) and (not ans[s-1] == c)) or (s == 1 and c == 0):
        print(-1)
        pf = False
        break
    else:
        ans[s-1] = c

if pf:
    if ans[0] == -1:
        ans[0] = 1
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
    print(''.join(map(str,ans)))
N, M = list(map(int, input().split()))
B = {}
for i in range(M):
  k, v = list(map(int, input().split()))
  if (k in B) and (B[k]!=v):
    print(-1)
    exit()
  else:
    B[k] = v
if (N!=1) and (B.get(1, 0)==0):
  print(-1)
  exit()
ans = ""
for i in range(1, N+1):
  ans = ans + str(B.get(i, 0))
print(ans)
def check(m, x):
  for i in range(m):
    s, c = map(int, input().split())
    
    if len(x) != 1 and s == 1 and c == 0:
      return -1
    elif x.get(s) == None or x.get(s) == c:
      x[s] = c
    else:
      return -1
  
  return "".join([str(v) if v else str(0) for v in x.values()])


n, m = map(int, input().split())
x = {i: None for i in range(1, n+1)}

print(check(m, x))
#graph implementation
import math
n,m=map(int,input().split())
ans=[0]*n
flag=False
for i in range(m):
    s,c=map(int,input().split())
    ans[s-1]=c
    if s-1==0:
        flag=True
#print(ans)
if not flag:
    ans[0]=1
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
N,M=map(int,input().split())
lst=[]
for i in range(M):
    lst.append(list(map(int,input().split())))
x=' '*N
for i in lst:
    if x[i[0]-1]==' ':
        x=x[:i[0]-1]+str(i[1])+x[i[0]:]
    elif int(x[i[0]-1])!=i[1]:
        x=-1
if type(x)==str:
    if x[0]==' ':
        x='1'+x[1:]
    x=x.replace(' ','0')
    if x[0]=='0' and len(x)!=1:
        x=-1
if M:
  print(x)
else:
  print(-1)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = 1000
for num in range(10 ** (n - 1), 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)
import sys


input = sys.stdin.readline

def main():
  n, m = map(int, input().rstrip().split())
  digits = [-1] * n
  for i in range(m):
    s, c = map(int, input().rstrip().split())
    if s > n:
      print(-1)
      return
    if digits[s-1] != -1 and digits[s-1] != c:
      print(-1)
      return
    digits[s-1] = c
  
  print("".join(["0" if _ == -1 else str(_) for _ in digits]))

if __name__ == "__main__":
  main()
o = input().split()
ans = ""
r = ["e" for i in range(int(o[0]))]
for i in range(int(o[1])):
  p = input().split()
  if r[int(p[0])-1] != "e" and r[int(p[0])-1] != p[1]:
    ans = "-1"
    break
  r[int(p[0])-1] = p[1]

if r[0] == "0":
  ans = "-1"
else:
  res =  ""
  for i in range(len(r)):
    res = res + str(r[i])
  if res.replace("e", "0").lstrip("0") == "":
    ans = "0"
  elif res[0] == "e":
    temp = list(res)
    temp[0] = "1"
    ans = "".join(temp)


print(ans)
N , M = input().split()
M = int(M)
N = int(N)
ans = ['0' for i in range (N)]
fl = True

for i in range (M) :
    s , c = input().split()
    s = int(s) - 1
    if (s == 0 and c == '0') :
        fl = False
    if (ans[s] != '0') :
        if (ans[s] != c) :
            fl = False
    else :
        ans[s] = c

res = ''

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

for i in ans :
    res += i

print (res if fl else -1)
#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)
for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(dig, dig*10):
    flag = False
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()
print("-1")
# coding: utf-8

N, M = list(map(int, input().split()))
if N == 0: N = 1
sc = [[i for i in map(int, input().split())] for j in range(M)]

flag = False
for i in range(10**(N-1), 10**N):
    for j in range(M):
        if str(i)[sc[j][0]-1] == str(sc[j][1]):
            flag = True
        else:
            flag = False
            break
    if flag == True:
        print(i)
        break
if flag == False: print(-1)
N, M = map(int, input().split(" "))
Field = [0 for i in range(N)]
count = 0
m = 0
for i in range(M):
    a, b = map(int, input().split(" "))
    a -=1
    if a == 0:
        m +=1
    if Field[a] != 0 and Field[a] != b:
        count+=1
    else:
        Field[a] = b
if m == 0:
    Field[0] = 1
if N != 1:
    if Field[0] == 0 or count !=0:
        print(-1)
    else:
        for i in Field:
            print(i, end="")
else:
    print(Field[0])
import math

N, M = map(int, input().split())
num = int(''.join(['9'] * N))

candidate = []
for i in range(1000):
    candidate.append(i)

for _ in range(M):
    s, c = map(int, input().split())
    tmp = []
    for n in candidate:
        if N != len(str(n)):
            continue
        if int(str(n)[s - 1]) == c:
            tmp.append(n)
    candidate = tmp

if candidate:
    print(candidate[0])
else:
    print(-1)
N,M = map(int,input().split())
k = [-1 for i in range(N)]
ng = 0
for i in range(M):
  s,c = map(int,input().split())
  if k[s-1] == -1:
    k[s-1] = c
  elif k[s-1] != c:
    ng = 1
    break
if k[0] == 0:
    ng = 1
if ng==1:
  print("-1")
else:
  if k[0] == -1:
    k[0] = 1
  for i in range(N):
    if k[i] == -1:
      k[i] = 0
  print("".join(map(str,k)))
n,m=map(int,input().split())
x=["0" for _ in range(n)]
for _ in range(m):
  s,c=map(int,input().split())
  if x[s-1] != '0' and x[s-1] != str(c):
    print(-1)
    break
  if s==1 and c==0:
    print(-1)
    break
  else:
    x[s-1] = str(c)
else:
  print("".join(x))
n,m = map(int, input().split())

sc = set([tuple(map(int, input().split())) for _ in range(m)])
ans = 0
h = []

for x,y in sc:
  if x == 1 and y == 0:
    print(-1)
    exit()
  if x in h:
    mini_b = 10**18
    for a,b in sc:
      if x == a:
        mini_b = min(mini_b, b)
    if mini_b > y:
        ans -= mini_b * (10 ** (n-x))
        ans += y * (10 ** (n-x))
  ans += y * (10 ** (n-x))
  h.append(x)

if ans < 10**(n-1):
  ans += 10**(n-1)
print(ans)
n,m=map(int,input().split())
num=[0 for i in range(n)]
for i in range(m):
  s,c=map(int,input().split())
  if s>n:
    num[0]=-1
  if n>0 and s==1 and c==0:
    num[s-1]=-1
  elif num[s-1]==0 or num[s-1]==c:
    num[s-1]=c
  else:
    num[s-1]=-1 
if num[0]==0:
  if n>1:
    num[0]=1
#print('    ',num)
moji=''
if min(num)>=0:  
  for i in range(n):
    moji+=str(num[i])
  print(int(moji))
else:
  print(-1)
N, M = map(int, input().split())

ans = ["x"]*N

for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if N != 1 and s == 0 and c == 0:
        print(-1)
        exit()
    if ans[s] == "x":
        ans[s] = str(c)
    else:
        if ans[s] != str(c):
            print(-1)
            exit()

if ans[0] == "x":
    ans[0] = "1"
for i in range(1,N):
    if ans[i] == "x":
        ans[i] = "0"

ans = "".join(ans)
print(ans)
N,M=map(int,input().split())
flag_n=[-1 for i in range(N)]
ans="1"+"0"*(N-1)
flag=True
for i in range(M):
    digit, num=map(int,input().split())
    if flag_n[digit-1]==-1 :
        flag_n[digit-1]=num
        ans=ans[digit-1:]+str(num)+ans[digit:]
    elif flag_n[digit-1]!=num:
        flag=False
        break
if False:
    print(-1)
elif N>1 and ans[0]=="0":
    print(-1)
else:
    print(int(ans))
n,m = map(int,input().split())
d = [0 for _ in range(n)]
d[0] = 1
sarr = []
for i in range(m):
    s,c = map(int,input().split())
    if s in sarr and c != d[s-1]:
        print(-1)
        exit()
    d[s-1] = c
    sarr.append(s)
ans = ''
for i in range(n):
    ans += str(d[i])
if ans[0] == '0':
    print(-1)
    exit()
print(ans)
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, *sc = map(int, read().split())
answer = [-1] * N

for s, c in zip(*[iter(sc)] * 2):
    s -= 1
    if answer[s] == -1:
        answer[s] = c
    else:
        if answer[s] != c:
            print(-1)
            exit()

if answer[0] == -1:
    answer[0] = 1
elif answer[0] == 0:
    if N != 1:
        print(-1)
        exit()

answer = [i if i != -1 else 0 for i in answer]
print(''.join(map(str, answer)))
n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]

for i in range(10*n):
    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())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
number_list = [10]*3
answer=0

for i in range(M):
    if number_list[S[i]-1] > C[i]:
        number_list[S[i]-1] = C[i]

number_list = [0 if i==10 else i for i in number_list ]

for i in range(N):
    answer += number_list[i]*10**(N-i-1)

if number_list[0] == 0 and N != 1:
    answer = -1

print(answer)
n,m=map(int,input().split())
ans=[0]*n
 
for i in range(m):
    a,b=map(int,input().split())
    
    if ans[a-1]==0 or ans[a-1]==b:
        ans[a-1]=b
    else:
        print(-1)
        exit()


if n>1 and ans[0]==0:
    print(-1)
elif n==1:
    print(ans)
elif n==2:
    print(10*ans[0]+ans[1])
else:
    print(100*ans[0]+10*ans[1]+ans[2])
N, M = map(int, input().split())
conditions = [tuple(map(int, input().split())) for _ in range(M)]
num = [0] * N
checked = [None] * N
for s, c in conditions:
    s -= 1
    if checked[s] is None:
        checked[s] = c
        num[s] = c
    else:
        if checked[s] == c: continue
        else:
            print(-1)
            break
else:
    print(''.join(str(n) for n in num) if num[0] != 0 else -1)
import sys
import math
import copy
import queue
input = sys.stdin.readline
n,m = map(int,input().split())
ans = list('0' * n)
for _ in range(m):
    s,c = input().split()
    ans[int(s)-1] = c

if ans[0] == '0':
    print (-1)
else:
    print (''.join(ans))
import sys

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

str_ans = ''

dict = {}

for i in range(m):
    s,c = map(int, input().split())
    if s in dict.keys():
        if c != dict.get(s, c):
            print(-1)
            sys.exit()

    dict[s] = c 


for j in range(1 , n + 1):
   str_ans = str_ans + str(dict.get(j, 0))

try:
    ans = int(str_ans)
except ValueError:
    print(-1)
    sys.exit()

if str_ans != str(ans):
    print(-1)
    sys.exit()

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

ans=[]
for i in range(n) :
    if C[i] :
        x=min(C[i])
        ans.append(str(x))
    else :
        x=0
        ans.append(str(x))
ans="".join(ans)
if ans[0]=="0" :
    print(-1)
elif m<n :
    print(-1)
else :
    print(ans)
n, m = (int(x) for x in input().split())
s, c = [], []

for i in range(m):
  _s, _c = (int(x) for x in input().split())
  s.append(_s)
  c.append(_c)

ans = ''
if n > m:
  print(-1)
else:
  for _n in range(1, n+1):
    if len([c[i] for i, _s in enumerate(s) if _s == _n]) == 0:
      ans += '0'
    else:
      ans += str(min([c[i] for i, _s in enumerate(s) if _s == _n]))
  if len(ans) == n and ans[0] != '0':
    print(ans)
  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 and n!=1) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a":N="1"+N[1:]
N=N.replace("a","0")
print(int(N))
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:
  print(-1)
  exit()
elif arr[0] == 10:
  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())
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(_)

if ans:
    print(min(ans))
else:
    print(-1)
import sys

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

ans = [-1] * N

for i in range(M):
	ind = s[i]-1
	num = c[i]

	if ans[ind] == -1:
		ans[ind] = num
	else:
		if ans[ind] != num:
			print(-1)
			sys.exit()

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

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

print(''.join(list(map(str, ans))))
n,m = map(int,input().split())
s = list(list(map(int,input().split())) for i in range(m))
x = [0]*n
b = True
ans = -1
for i in range(m):
    if x[s[i][0]-1] == 0 or x[s[i][0]-1] == s[i][1]:
        x[s[i][0]-1] = s[i][1]
    else:
        b = False
if x[0] == 0:
    b = False
ans = ''.join([str(c) for c in x]) if b else -1
print(ans)
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 1 not in d.keys():
    if M != 0:
        d[1] = 1
    else:
        d[1] = 0
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")
N,M=map(int,input().split())

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

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

print(int("".join(map(str,ans))))
N, M = map(int, input().split())
sc_dict = {}
for i in range(M):
    s, c = map(int, input().split())
    if sc_dict.get(s) is not None:
        if sc_dict.get(s) != c:
            print(-1)
            exit(0)
    else:
        sc_dict[s] = c

ans = ""
for i in range(N):
    ans += "0"
ans = list(ans)

for k, v in sc_dict.items():
    ans[k-1] = str(v)

ans = int("".join(ans))

if ans == 0:
    print(-1)
else:
    print(ans)
N, M = map(int, input().split(' '))

ans = [-1] * N

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


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

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

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

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

print(ANS)
n,m = map(int,input().split())
L = [input().split() for i in range(m)]

for i in range(m):
    L[i] = [int(x) for x in L[i]]
    
flag = False
for i in range(100,1000):
    i = str(i)
    for j in range(m):
        if i[L[j][0]-1] == str(L[j][1]):
            flag = True
        else:
            flag = False
            break
    if flag:
        print(i)
        exit()
print(-1)
n, m = (int(x) for x in input().split())
ans = [None for _ in range(n)]
fail = False
for _ in range(m):
    s,c = (int(x) for x in input().split())
    s -=1
    if ans[s] is None:
        ans[s] = c
    elif ans[s] != c:
        fail = True
        break
if fail or ans[0] == 0:
    print(-1)
else:
    if ans[0] is None:
        ans[0] = 1
    print(''.join((str(i) if i is not None else '0' for i in ans)))
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:
        break

    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)
N,M = map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(M)]
sc = set(sc)

ans = -1
for i in range(1001):
    num = str(i).rjust(3,'*')
    for s,c in sc:
        if ( not num[s-1].isdigit() ) or ( int(num[s-1]) != c ):
            break
    else: ans = i
    if ans != -1:
        break

print(ans)
n,m=map(int,input().split())
x=[]
for _ in range(n):
    x.append([])

for _ in range(m):
    s,c=map(int,input().split())
    x[s-1].append(c)
ans=''
for i in range(n):
    if len(x[i])==0 and i==0:
        ans='-1'
        break
    elif len(x[i])==0 and i!=0:
        ans+='0'
    elif len(set(x[i]))>=2:
        ans='-1'
        break
    else:
        ans+=str(x[i][0])
print(ans)
def abc157c(n, m, sc):
    ans = [0 for _ in range(n)]
    if (1,0) in sc:
        return -1
    for s, c in sc:
        if ans[s-1] and ans[s-1]!=c:
            return -1
        else:
            ans[s-1]=c
    _ans = ""
    return _ans.lstrip('0')
  
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
print(abc157c(n,m,sc))
N, M = map(int, input().split())
P = [list(map(int,input().split())) for i in range(M)]

ans = -1

for x in range(700, 704):
    if len(str(x)) != N: 
        continue
    else:
        count = 0
        s = str(x)
        for p in P:
            if int(s[int(p[0]) - 1]) == p[1]:
                count += 1
        if count == M:
            ans = x
            break

print(ans)
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


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

if __name__ == "__main__":
	main()
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    digit = si - 1
    if answer[digit] is not None and answer[digit] != ci:
        print('-1')
        exit()
    
    answer[digit] = ci

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

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

answer = ''.join(map(str, answer))
print(answer)
n, m = map(int, input().split())
s_li = [list(map(int, input().split())) for i in range(m)]

ans = ['0'] * n
flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and ans[s - 1] == '{}'.format(c):
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

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

o=[10]*3

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

if o[0]==0:
  print("-1")
  exit()
if o[0]==10 and o[1]==10:
  print(o[2])
  exit()

if o[0]==10:
  print(o[1],end="")
  print(o[2])
  exit()

for i in range(0,3):
  if o[i]==10:
    print(0,end="")
  else:
    print(o[i],end="")