N,M=map(int, input().split())
num=[0]*N
reg=[0]*N
ans=0

for i in range(M):
	s, c=map(int, input().split())
	if reg[s-1]==1 and num[s-1]!=c:
		ans=-1
		break
	else:
		num[s-1]=c
		reg[s-1]=1

#print(num)
#print(reg)

if num[0]==0:
	ans=-1
else:
	for j in range(N):
		ans+=num[j]*10**(N-j-1)

print(ans)