f=0
N, M = map(int, input().split())
list = []
for i in range(M):
    a,b=input().split()
    list.append((int(a), int(b)))

for i in range(1000):
	f=0
	for j in range(M):
		if int(i/(10**(N-list[j][0])))%10 != list[j][1]:
			f=1
			break
	if f==0:
		print(i)
		break
		
if f==1:
	print(-1)