import numpy as np 

N, M = map(int, input().split())

data = np.array([0 for i in range(N)])

error = 0

for i in range(M):
	x, y = map(int, input().split())
	if data[x-1] != y and data[x-1] != 0 and y != 0:
		error = 1
		break
	else:
		data[x-1] = y

if error == 1 or (data[0] == 0 and len(data) != 1):
	print(-1)
else:
	L=[str(a) for a in data]
	L="".join(L)
	print(L)