N, M = map(int, input().split())
from collections import defaultdict
dd=defaultdict(int)
dd_count=defaultdict(int)

for _ in range(M):
	s, c = map(int, input().split())
	#異なるものが2個ある
	if dd_count[s-1]>=1 and dd[s-1]!=c:
		exit(print(-1))
	else:
		dd[s-1]=c
		dd_count[s-1]+=1


ans=""
for i in range(N):
	ans+=str(dd[i])
ans=int(ans)
print(ans if ans//10*(N-1)!=0 else -1)