n,m = list(map(int,input().split()))
arr = []
for i in range(n):
	arr.append(0)
for i in range(m):
	x,y = list(map(int,input().split()))
	arr[x-1] = y
ans = ""
for i in range(len(arr)):
	if arr[i]>0:
		ans = "".join([str(k) for k in arr[i:]])
		break
else:
	ans = "-1"
if len(ans)==n:
	print(ans)
else:
	print("-1")