import numpy as np
import sys
list = [int(i) for i in input().split()]
a=list[0]
b=list[1]
 
tablec = np.array([[int(i) for i in input().split()] for b in range(b)])
tablea =[0,0,0]
i=0
w=0
x=0
y=0
z=0
ans=0
for i in range(b):
	x=tablec[i,0]
	y=tablec[i,1]
	w=tablea[x-1]
	if w != y and w!=0: 
		ans=-1
	elif w==0:
		tablea[x-1]=y
if ans != -1:
	x=tablea[0]
	y=tablea[1]
	z=tablea[2]
	if x==0 and b==3:
		x=1
	if y==0 and b==2:
		y=1
	if z==0 and b==1:
		z=1
	ans=x*100+y*10+z
print(ans)