import sys
n,m=map(int,input().split())
n=str(10**(n-1))
x=[0,0,0]
for _ in range(m):
  a,b=input().split()
  if x[int(a)-1]==0:
    n=n[:int(a)-1]+b+n[int(a):]
    x[int(a)-1]=1
  else:
    if n[int(a)-1]!= b:
      print(-1)
      sys.exit()
if n[0]=="0":
  print(-1)
else:
  print(n)

      