n,m = map(int,input().split())
keta = []
number = []

for i in range(m):
    n,a=input().split()
    keta.append(int(n))
    number.append(a)

ccount = 0
count = 0   
ans = 0
if n == 3:
   ans = 100
if n == 2:
   ans = 10
if n == 1:
   ans = 0

while count == 0:
   ans = str(ans)
   for i in range(0,m):
      if ans[keta[i]-1] == number[i]:
         ccount += 1
   if ccount == m:
      count += 1
   ccount = 0
   ans = int(ans)
   ans += 1
   if n = 3 and (ans - 1) == 1000:
      ans = 0
      break
   if n = 2 and (ans - 1) == 100:
      ans = 0
      break
   if n = 1 and (ans - 1) == 10:
      ans = 0
      break
print(ans - 1)