N,M=map(int, input().split())
s=[0]*M
c=[0]*M
x=[0]*M
h=0
y=0
z=1
for i in range(M):
	s[i],c[i]=map(int, input().split())
	y=s[i]-1
	x[y]=c[i]
if len(x)==N:
	x.reverse()
	for j in x:
		h=h+j*z
		z=10*z
	print(h)
else:
	print('-1')