peterverebics/CodeNet_Python_118 huggingface dataset:
n, m = [int(i) for i in input().split()]
a = [10] * n
for i in range(m):
    s, c = [int(i) for i in input().split()]
    s -= 1
    a[s] = min(c, a[s])

if a[0] == 10 or n >= 2 and a[0] == 0:
    print("-1")
else:
    ans = ""
    for i in a:
        if i == 10:
            ans += "0"
        else:
            ans += str(i)
    print(ans)
import numpy as np

N,M = input().split(' ')
N = int(N)
M = int(M)

res = np.zeros(N, dtype=np.int)
res -= 1
for i in range(M):
  keta, v = input().split(' ')
  keta = int(keta) - 1
  v = int(v)
  if res[keta] == -1:
    res[keta] = v
  elif res[keta] > v:
      res[keta] = v

res += (res == -1) * 1

if N == 1:
  print(res[0])
elif res[0] > 0:
  x = [str(x) for x in res]
  x = ''.join(x)
  print(x)
else:
  print('-1')
def resolve():
    n, m = map(int, input().split())
    ans = [-1] * n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s - 1] not in (-1, c):
            print(-1)
            return
        ans[s - 1] = c
    if ans[0] == 0 and n != 1:
        print(-1)
        return
    print("".join([str(x) if x > 0 else "0" for x in ans]))


if __name__ == '__main__':
    resolve()
n, k =map(int, input().split())
data = []
for i in range(k):
    data.append(list(map(int, input().split())))
for i in range(10**(n-1), 10**n):
    a = str(i)
    tmp = True
    for i in data:
        data1 = i[0]
        data2 = i[1]
        #print(data1, data2)
        if(a[data1-1] != str(data2)):
            tmp=False
    if(tmp):print(a);exit()
print(-1)
n,m = map(int, input().split())
ans = ['0']*n
aa = {}
if m==0 or n<m:
    print(-1)
    exit()
for i in range(m):
    s, c = map(int, input().split())
    if s in aa.keys() and aa[s]!=c:
        print(-1)
        exit()
    ans[s-1]=str(c)
    aa[s] = c
ans = int(''.join(ans))
print(-1 if n>=2 and ans==0 else ans)
import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)

ans = np.full(N+1, -1)
for i in range(M):
  if((ans[s[i]]==-1)or(ans[s[i]]==c[i])):
    ans[s[i]] = c[i]
  else:
    print(-1)
    sys.exit()
ans = np.where(ans==-1, 0, ans)
if(ans[1]==0):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))
n, m = map(int, input().split())
res = [0] * n
for i in range(m):
    s, c = map(int, input().split())
    if res[s-1] != 0:
        print(-1)
        exit(0)
    res[s-1] = c

ans = str(int(''.join(map(str, res))))
if len(ans) != n:
    print(-1)
else:
    print(ans)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
a=[-1]*n
ans=1
for i in range(len(sc)):
  if a[sc[i][0]-1]==-1:
    a[sc[i][0]-1]=sc[i][1]
  else:
    if a[sc[i][0]-1]!=sc[i][1]:
      ans=0
      break
ll=""
for j in range(n):
  if a[j]==-1:
    a[j]=0
  ll+=str(a[j])
if ans==0:
  print(-1)
else:
  if n!=len(str(int(ll))):
    print(-1)
  else:
    print(int(ll))
N,M = list(map(int, input().split()))
s = []
c = []
for i in range(M):
  inputs = list(map(int, input().split()))
  s.append(inputs[0])
  c.append(inputs[1])

res = [0 for i in range(N)]
for digit, number in zip(s,c):
  digit -= 1
  res[digit] = number

convert = list(map(str, res))
res = int("".join(convert))
if len(str(res)) == N:
  print(res)
else:
  print(-1)
n,m=map(int,input().split())
l=[]
l1=[]
flag=0

for i in range(n):
  l.append(0)
  l1.append(0)

for i in range(m):
  a,b=map(int,input().split())
  
  if l1[a-1]!=0 and l[a-1]!=b:
    flag=1
    break

  else:
    l[a-1]=b
    l1[a-1]=1
 # print(l1[a-1],l[a-1])

s=str()
for i in range(n):
  s+=str(l[i])

#print(s,flag)
if n==1 and flag==0:
  print(s)
elif flag==0 and s[0]!='0':
  print(s)
else:
  print(-1)
in1 = input('')
n = int(in1.split(' ')[0])
m = int(in1.split(' ')[1])
l = []
for i in range(0,n):
  l.append(0)

for i in range(0,m):
  in2 = input('')
  idx = int(in2.split(' ')[0])-1
  li = int(in2.split(' ')[1])
  l[idx] = li

result = 0
for i in range(0,n):
  ix = 1
  for j in range(0,(n-i-1)):
    ix *=10
  result += int(l[i])*ix
if len(str(result)) != n:
  result = "-1"
print(result)
# ACB157 C

n, m = map(int, input().split())
res = ["0"] * n

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

if res == -1:
    print(res)
else:
    if res[0] == "0":
        res[0] == "1"
    print(int("".join(res)))
s_text = list(map(int, input().split()))
output = [0] * s_text[0]
flag = True
for i in range(s_text[1]):
    text = list(map(int, input().split()))

    if text[0] == 1 and text[1] == 0 and s_text[0] != 1:
        flag = False
    if output[text[0] - 1] == 0 or output[text[0] - 1] == text[1]:
        output[text[0] - 1] = text[1]
    else:
        flag = False

if output == [0] * s_text[0] and s_text[0] != 1:
    output[0] = 1

if flag:
    print("".join(map(str, output)))
else:
    print("-1")
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append(list(map(int, input().split())))

minimum = [10]*n

for i in range(m):
    minimum[l[i][0]-1] = min(l[i][1], minimum[l[i][0]-1])


if minimum[n-1] == 10 or (n != 1 and minimum[n-1] == 0):
    print(-1)
    quit()

for i in range(n):
    if minimum[i] == 10:
        minimum[i] = '0'
    else:
        minimum[i] = str(minimum[i])

print(('').join(minimum))
N , M = map(int,input().split())
ans = ["0" for _ in range(N)]
for i in range(M):
    s , c = map(int,input().split())
    ans[s - 1] = str(c)
if len(str(int("".join(ans)))) == N:
    print(int("".join(ans)))
else:
    print("-1")
import sys
N, M = map(int, input().split(" "))
Field = [0 for i in range(N)]
count = 0
for i in range(M):
    a, b = map(int, input().split(" "))
    a -=1
    if Field[a] != 0 and Field[a] != b:
        count+=1
    else:
        Field[a] = b
if N != 1:
    if Field[0] == 0 or count !=0:
        print(-1)
    else:
        for i in Field:
            print(i, end="")
else:
    print(Field[0])
# -*- coding: utf-8 -*-

N, M = map(int, input().split())

S = []
C = []

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


X = [None for i in range(N)]

for j in range(M):
    value = C[j]
    i = S[j] - 1

    if X[i] is None:
        X[i] = value
    elif X[i] != value:
        print(-1)
        exit(0)

if X[0] == 0 and N >= 2:
    print(-1)
else:
    X[0] = X[0] or 1
    print(''.join(['{}'.format(x or 0) for x in X]))
n, m = map(int, input().split())

num = [0]*3
flag = [0]*3

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

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

if len(num) == n:
    print("".join(list(map(str, num))))
else:
    print(-1)
n,m = [int(v) for v in input().split()]
sc = [[int(v) for v in input().split()] for _ in range(m)]

ans = [0 for _ in range(n+1)]
flag = True

for (s,c) in sc:
    if s > n: flag = False
    elif ans[s] != 0 and ans[s] != c: flag = False
    else: ans[s] = c

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

if flag:
    for v in ans[1:]:
        print(v,end='')
else:
    print(-1)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif not ans[s] == c:
        print(-1)
        exit()
a = 0
for i in range(N):
    if ans[i] is -1:
        ans[i] = 0
    a += ans[i]*10**(N-i-1)

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

print(a)
N, M = map(int, input().split(' '))
rst_ls = [0] * N
rst = ''
if M == 0:
    rst = '1' + '0' * (N - 1)
    print(rst)
else:
    for i in range(M):
        ls = list(map(int, input().split(' ')))
        rst_ls[ls[0] - 1] = ls[1]
    for i in rst_ls:
        rst += str(i)
    rst = int(rst)
    if N == len(str(rst)):
        print(rst)
    else:
        print(-1)
n, m = map(int, input().split())
order = []
num = [-1 for i in range(n)]
for i in range(m):
  tmp = [int(i) for i in input().split()]
  order.append(tmp)

flag = True
for od in order:
  if num[od[0]-1] == -1:
    num[od[0]-1] = od[1]
  else:
    if num[od[0]-1] != od[1]:
      flag = False

if num[0] == 0 and n != 1:
  flag = False
else:
  for i in range(n):
    if num[i] == -1:
      num[i] = "0"
    else:
      num[i] = str(num[i])
      
if flag:
  print("".join(num))
else:
  print(-1)
from collections import defaultdict

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

number = defaultdict(int)
for s, c in sc:
    if s in number and c != number[s]:
        print(-1)
        exit()
    number[s] = c

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

if res == 0:
    print(0)
elif res < 10 ** (n - 1):
    print(-1)
else:
    print(res)
n,m = map(int,input().split())
t = [0 for i in range(n)]
b = ""
a = True
for i in range(m):
    s,c = map(int,input().split())
    if t[s-1] != 0 and c == 0:
        a=False
    elif t[s-1] == 0 or t[s-1] == c:
        t[s-1] = c
    else:
        a=False
for i in range(n):
    b += str(t[i])
if n > 1 and b[0] == '0':
    print(-1)
elif b[0] == '0':
    print(0)
elif a:
    print(b)
else:
    print(-1)
N, M = map(int,input().split())

num_dict = {1: 0, 2: 0, 3: 0}
i = 0
for _ in range(M):
    temp1, temp2 = map(int,input().split())
    if num_dict[temp1] > temp2 or i == 0:
    	num_dict[temp1] = temp2
    i += 1

if num_dict[1] == 0 and N != 1:  
    print(-1)
else:
    print("".join([str(num_dict[i+1]) for i in range(N)]))
n, m = map(int, input().split())
x = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if x[s] != -1 and x[s] != c or s == 0 and c == 0:
        print(-1)
        quit()
    x[s] = c
if x[0] == -1:
    x[0] = 1
for i in range(1, n):
    if x[i] == -1:
        x[i] = 0
print(''.join(map(str, x)))
N, M = list(map(int, input().split()))
digits = [-1 for i in range(N)]

fail = False

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

    if (digits[s] != -1 and digits[s] != c):
        fail = True
    elif s >= N:
        fail = True
    else:
        digits[s] = c

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

if digits[0] == 0:
    fail = True
    
if fail:
    print(-1)
else:
    print("".join(map(str, digits)))
n,m = map(int, input().split())
lis = []
for i in range(m):
    lis.append(list(map(int, input().split())))
    
s =[0]*n
for j in lis:
    s[j[0]-1] = j[1]
    
stli = ""
for i in s:
    stli += str(i)

flag = 0
for k in range(10**n):
    if str(k) == stli:
        flag = 1
        break

if flag or stli =="0" or stli == "00" or stli == "000":
    print(stli)
else:
    print(-1)
n, m = [int(i) for i in input().split(' ')]
sc = [[int(i) for i in input().split(' ')] for j in range(m)]
sc = list(map(list, set(map(tuple, sc))))
s = [i[0] for i in sc]
c = [i[1] for i in sc]

fl1 = len(set(s)) != len(s)
if (1 in s) & (m != 1):
  fl2 = c[s.index(1)]==0
else:
  fl2 = False

if (n==1) & (m==0):
  print('0')
elif fl1 | fl2:
  print('-1')
else:
  ans = ['0' for i in range(n)]
  if 1 not in s:
    ans[0] = '1'
  for i in sc:
    ans[i[0]-1] = str(i[1])
  print(''.join(ans))
N,M = input().split(' ')
numlist = []
for i in range(int(N)):
    numlist.append('0')
for i in range(int(M)):
    S,C = input().split(' ')
    numlist[int(S)-1] = C
num = ''.join(numlist)
num = int(num)
if N != 1:
    if len(str(num)) == int(N):
        print(int(num))
    else:
        print(-1)
else:
    print(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()
  num[s-1] = c
  
for i in range(n):
  if num[i] == -1:
    num[i] = 0
    
ans = ""
for i in num:
  ans += str(i)
if len(str(int(ans))) != n:
  print(-1)
else:
  print(ans)
n,m = map(int, input().split())
l = [[] for _ in range(n)]
ans = ""
for i in range(m):
  s,c = map(int, input().split())
  l[s-1].append(c)
if len(l) > 1 and 0 in l[0]:
  print(-1)
else:
  for j in l:
    if len(set(j)) > 1:
      print(-1)
      break
    elif len(j) == 0:
      if j == l[0]:
        ans += "1"
      else:
        ans += "0"
    else:
      ans += str(j[0])
  else:
    print(ans)
n,m = map(int,input().split())

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

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

num_ =''
num = list(map(str,num))
for i in range(n):
    num_ += num[i]

print(int(num_))
N, M = map(int, input().split())
#SC = [list(map(int, input().split())) for i in range(M)]
define = [0] * N
ans = [0] * N

for i in range(M):
  s, c = map(int, input().split())
  if define[s - 1] == 1:
    #print("y")
    if c != ans[s-1]:
      print("-1")
      quit()
  else:
    define[s - 1] = 1
    ans[s-1] = c

if ans[0] == 0:
  print("-1")
  quit()
  
for i in range(N):
  print(ans[i], end = "")
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
# n桁
# m個の要求
# 左からs桁目はc

ans = [0]*n
check = 0

for i in range(0,m):
  if ans[a[i][0]-1] == 0 or ans[a[i][0]-1] == a[i][1]:
    ans[a[i][0]-1] = a[i][1]
  else:
    check += 1

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

if check == 0 and len(str(ans)) == n:
  print(ans)
else:
  print(-1)
n,m = map(int,(input().split()))
sc = [list(map(int,input().split())) for _ in range(m)]

num = [0,0,0]
cnt = 0
for i in range(m):
    keta = sc[i][0] - 1
    if num[i] < sc[i][1]:
        num[keta] = sc[i][1]


result = str(num[0]) + str(num[1]) + str(num[2]) 
result = int(result)

keta = (len(str(result)))

if n > keta:
    print("-1")
else:
    print(result)
N,M = input().split(' ')
numlist = []
for i in range(int(N)):
    numlist.append('0')
for i in range(int(M)):
    S,C = input().split(' ')
    numlist[int(S)-1] = C
num = ''.join(numlist)
num = int(num)
if int(N) == 1:
    if len(str(num)) == int(N):
        print(int(num))
    else:
        print(0)
else:
    if len(str(num)) == int(N):
        print(int(num))
    else:
        print(-1)
n, m = map(int, input().split())
a, b, num = [0]*m, [0]*m, [0]*n
num[0]=1
for i in range(m):
  a[i], b[i] = map(int, input().split())
  num[a[i]-1]=b[i]
for i in range(m):
  if num[a[i]-1]!=b[i]:
    print(-1)
    exit()

ans=''
for i in num:
  ans+=str(i)
ans = int(ans)
ans = str(ans)
if len(ans)==n:
  print(ans)
else:
  print(-1)
N,M=map(int,input().split())
ans=[0]*N
guess=0
num=0
for _ in range(M):
    s,c=map(int,input().split())
    if ans[s-1]!=0 and ans[s-1]!=c:
        guess=1
        break
    elif s==1 and c==0:
        guess=1
        break
    else:
        ans[s-1]=c
if guess==0:
    if ans[0]==0:
        ans[0]=1
    for i in range(N):
        num+=ans[i]*(10**(N-1-i))
    print(num)
else:
    print(-1)
n,m = map(int, input().split())
a = [-1 for i in range(n)]
for i in range(m):
    s,c = map(int, input().split())
    s -= 1
    if s == 0 and c == 0:
        print(-1)
        exit()
    if a[s] != -1 and c != a[s]:
        print(-1)
        exit()
    a[s] = c

if a[0] == -1:
    a[0] = 1
for i in range(1, n):
    if a[i] == -1:
        a[i] = 0
ans = 0
for i in a:
    ans = ans * 10 + i
print(ans)
n, k =map(int, input().split())
data = []
for i in range(k):
    data.append(list(map(int, input().split())))
for i in range(10**(n-1), 10**n):
    a = str(i)
    tmp = True
    for i in data:
        data1 = i[0]
        data2 = i[1]
        #print(data1, data2)
        if(a[data1-1] != str(data2)):
            tmp=False
    if(tmp):print(a);exit()
if(n==1):print(0)
else:print(-1)
N, M = map(int, input().split())
S = [0]*N
for _ in range(M):
  s, c = map(int, input().split())
  if S[s-1] == c:
    continue
  elif S[s-1] == 0:
    S[s-1] = c
  elif S[s-1] != c:
    print(-1)
    exit()

if S[0] == 0 and len(S)==1:
  print(0)
elif S[0] == 0:
  print(-1)
else:
  print(''.join(map(str, (S))))
n,m = (int(i) for i in input().split())
number = [0] * n
numberFlag = [0] * n
answer = 0
result = ""
for i in range(m):
	s,c = (int (i) for i in input().split())
	if s == 1 and c == 0 and n > 1:
		answer = -1
		break
	elif number[s-1] != c and numberFlag[s-1] == 1:
		answer = -1
		break
	elif numberFlag[s-1] == 0:
		number[s-1] = c
		numberFlag[s-1] = 1
	
if answer == -1:
	print(answer)
else:
	for i in range(n):
		if not result and i != n-1 and number[i] == 0:
			continue
		result += str(number[i])
	print(result)
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):
    S = str(i)

    if len(S) != N:
        continue

    for j in range(M):
        if int(S[s[j]-1]) != c[j]:
            break
        if j == M-1 and (N == 1 or int(S[0]) != 1):
            print(S)
            sys.exit()

print(-1)
n, m = map(int, input().split())
num = [0]*n

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


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

if len(str(ans)) == n:
    print(ans)
else:
    print(-1)
import sys
import numpy as np
n,m = map(int, input().split())
s = list()
c = list()
for i in range(m):
    a,b = map(int, input().split())
    if not a in s:
        s.append(a)
        c.append(b)
    else:
        c[s.index(a)] == min(b,c[s.index(a)])
if not 1 in s or c[s.index(1)] == 0:
    print('-1')
    sys.exit()
result = 0
for i,v in zip(s,c):
    result += (10**(n - i))*v
if result != 0:
    print(str(result))
else:
    print('-1')
N,M = map(int,input().split())
ans = [-1]*N
flg = 0
 
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if ans[s] == -1 or ans[s] == c:
    ans[s] = c
  else:
    flg = 1
  
if flg == 0:
  if N == 1 and ans[0] == -1:
    print("0")
  elif ans[0] == 0:
    print("-1")
  else:
    for i in range(N):
      if ans[i] == -1:
        ans[i] = 0
    print(int("".join(map(str,ans))))
else:
  print("-1")
vs = input().split(' ')
N = int(vs[0])
M = int(vs[1])
valueMap = [10 for i in range(N)]

for i in range(M):
  vs = input().split(' ')
  t_i = int(vs[0]) - 1
  t_v = int(vs[1])

  if (valueMap[t_i] == 10 and valueMap[t_i] != t_v):
    valueMap[0] = 0
    break

  if (valueMap[t_i] > t_v and t_v != 0):
    valueMap[t_i] = t_v
valueMap = list(map(lambda v: 0 if v == 10 else v, valueMap))

if (len(valueMap) != 1 and valueMap[0] == 0):
  print(-1)
else:
  print("".join(map(str, valueMap)))
import sys

N, M = [int(x) for x in input().split()]
guess = [-1] * (N + 1)
check = True
for i in range(M):
  s, c = [int(x) for x in input().split()]
  if guess[s] != -1 and guess[s] != c:
    check = False
  else:
    guess[s] = c


if guess[1] <= 0 :
  check = False
      
if not check:
  print(-1)
  sys.exit()
  
result = 0
y = N
for i in range(1, N+1):
  val = 0 if guess[i] == -1 else guess[i]
  result += 10 ** (y-1) * val
  y -= 1

print(result)
n,m=(int(i) for i in input().split())
l=[0,None,None]
answer='unknown'
for i in range(m):
  a,b=(int(i) for i in input().split())
  if l[n-a]==None:
    l[n-a]=b
  elif l[n-a]!=b:
    answer='-1'
    break
for i in range(3):
  if l[i]==None:
    if i!=n-1:
      l[i]=0
    else:
      l[i]=1
r=l[2]*10**2+l[1]*10+l[0]
if len(str(r))!=n:
  answer='-1'
if answer=='-1':
  print('-1')
else:
  print(r)
import sys
n, m = map(int, input().split())
num = [-1]*n

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

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

  # 一桁目が0
  if s == 1 and c == 0:
    print(-1)
    sys.exit()
  # 同じ桁が指定される
  if num[s-1] != -1 and num[s-1] != c:
    print(-1)
    sys.exit()
  num[s-1] = c

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

for i in num:
  print(i, end='')
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for i in range(10**(n-1),10**n):
    i=str(i)
    for s,c in sc:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        break
print(-1)
n , m = map(int,input().split())
x = [0]
y = [0]
z = [0]

for i in range(m):
    s , c = map(int,input().split())
    if s ==1:
        x.append(c)
    elif s==2:
        y.append(c)
    elif s == 3:
        z.append(c)

if len(set(x))==1:
    print(-1)
elif len(set(x)) >= 3 or len(set(y)) >= 3 or len(set(z)) >=3:
    print(-1)
else: 
    print(max(x)*100 + max(y)*10 + max(z))
def main():
  N, M = map(int,input().split())
  dct = {}
  ans = [0]*N
  for _ in range(M):
    s, c = map(int,input().split())
    ans[s-1]=c
    if s==1 and c==0 and N>=2:
      print(-1)
      return
    elif s not in dct:
      dct[s] = c
    else:
      if dct[s]!=c:
        print(-1)
        return 
  if ans[0]==0:
    ans[0]=1
  res = 0
  for i in ans:
    res*=10
    res+=i
  print(res)
  return
main()
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n,m=sep()
def f():
    return -1
ar=[]
for _ in range(m):
    ar.append(tuple(sep()))
t=0

def istrue(n):
    s=str(n)
    for i in ar:
        if i[0]>len(s):
            return 0
        if s[i[0]-1]!=str(i[1]):
            return 0
    return 1






for i in range(10**(n-1),10**n):
    if istrue(i):
        print(i)
        quit()
print(-1)
n,m = map(int,input().split())
ns = list('1' + '0'*(n-1))

s = [0]*m
c = [0]*m

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

if len(ns) > 1 and ns[0] == '0':
    ans = -1
else:
    ans = ''.join(ns)
print(ans)
N, M = map(int, input().split())
ans = 0

d={}

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

if ans == -1:
  print(ans)
else:
  for i in range(N):
    if i+1 in d:
      print(d[i+1], end='')
    elif i+1 == 1:
      print('1', end='')
    else:
      print('0', end='')
import sys
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(int)

for i in range(M):
    s, c = map(int, input().split())
    if (d[s]!=0) & (d[s]!=c):
        print(-1)
        sys.exit()
    elif ((s==1) & (c==0)) & (N != 1):
        print(-1)
        sys.exit()
    elif d[s]==0:
        d[s] = c
    else:
        continue

ans = ["1"] + ["0"] * (N - 1)

for s, c in d.items():
    ans[int(s) - 1] = str(c)

print("".join(ans))
n,m=map(int,input().split())
a=[]
for _ in range(m):
    s,c=map(int,input().split())
    a.append([s,c])

ans='-1'
for i in range(10**n):
    x=str(i)
    x=x.zfill(3)
    c=0
    for j in range(m):
        if x[a[j][0]-1] == str(a[j][1]):
            c+=1
    if c==m:
        ans=i
        break
print(ans)
from sys import exit

N,M = map(int,input().split())

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

for i in range(10**(N-1),10**N):
    strnum = str(i)
    flag = True
    for j in Query:
        if strnum[j[0]-1] != str(j[1]):
            flag = False
            break
        else:
            None
    if flag:
        print(i)
        exit(0)

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

for s, c in sc:
    if s in l and ans[s-1] != c:
        print("-1")
        exit()
    ans[s-1] = c
    l.append(s)

if 0 == ans[0] and len(ans) > 1:
    print("-1")
    exit()

print(''.join(map(str,ans)))
N, M = list(map(int, input().split(' ')))
ret = [-1 for i in range(N)]
error = False
for m in range(M):
    si, ci = list(map(int, input().split(' ')))
    if ret[si-1] == -1:
        ret[si-1] = ci
    elif ret[si-1] != ci:
        error = True
        break
tmp = ''
if not error:
    for n in range(N):
        if ret[n] == -1:
            ret[n] = 0
        tmp += str(ret[n])
    result = int(tmp)
    result = result if len(str(result)) == N else -1
else:
    result = -1
print(result)