X = input().split()
N = int(X[0])
M = int(X[1])
sc = []
 
 #リストscの[偶数]には桁、[奇数]には数字
for r in range(M):
  sc += input().split()

#scをint化
insect = [int(i) for i in sc]

k = 1
for r in range(N-1):
	k *= 10 
	ans = -1
#10^N以下について調べる
for r in range(k, k*10, 1):
	U = list(str(r))
	t = 0
	for s in range(M):
		if U[insect[2*s]-1] == str(insect[2*s+1]):
			t += 1
	if t == M:
		ans = r
		break

print(ans)