N,M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(M)]

tmp='0'*N
list_s=[]
cnt=0
for i in range(M):
	if a[i][0]==1 and a[i][1]==0:
		print(-1)
		break
	else:
		if a[i][0] in list_s and tmp[a[i][0]-1] != a[i][1]:
			print(-1)
			break
		else:
			cnt+=1
			tmp = tmp[:a[i][0]-1]+str(a[i][1])+tmp[a[i][0]:]
			list_s.append(a[i][0])
			#tmp[a[i][0]-1].replace(str(a[i][1]))
if cnt==M and M!=0:
	print(tmp)
if M==0:
	tmp = str(1) + tmp[1:]
	print(tmp)