N,M=map(int,input().split())
s_l=[]
c_l=[]
ans=0
order_l=[-1]*3
if M==0 and N>1:
	print(10**(N-1))
	exit()
if M==0 and N==1:
	print(0)
	exit()
for _ in range(M):
	S,C=list(map(int,input().split()))
	s_l.append(S-1)
	c_l.append(C)
for i in range(M):
	if order_l[s_l[i]] ==-1 or order_l[s_l[i]] ==c_l[i]:
		order_l[s_l[i]]=c_l[i]
	else:
		print(-1)
		exit()
if order_l[0]==0 and M>1:
	print(-1)
	exit()
order_l[1]=max(0,order_l[1])
order_l[2]=max(0,order_l[2])
if N>1:
  ans=order_l[0]*10**(N-1)+order_l[1]*10**(N-2)+order_l[2]*(max(0,N-2))
else:
  ans=order_l[0]
print(ans)