import sys
n = list(map(int,input().split()))
a=[0,0,0]
for i in range(n[1]):
  s,c=map(int,input().split())
  if a[s-1]==0:
    a[s-1]=c
  elif a[s-1]!=c:
    print('-1')
    sys.exit()
if n==3:
  if a[0]==0:
    print('-1')
  else:
    for a_ in a:
      print(a_, end='')
elif n==2:
  if a[0]!=0 or a[1]==0:
    print('-1')
  else:
    for a_ in a:
      print(a_, end='')
else:
  for a_ in a:
    print(a_, end='')