n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

num=[0]*3

for i in l:
  if num[i[0]-1]==0 or num[i[0]-1]==i[1]:
    num[i[0]-1]=i[1]
  else:
    print(-1)
    exit()
    
if (n==3 and num[0]!=0) or (n==2 and num[1]!=0) or (n==1 and num[2]!=0):
  print(*num,sep='')
else:
  print(-1)
    
