N,M = map(int, input().split())
L = []
ans = []
for i in range(M):
	L.append(list(map(int, input().split())))
	ans.append(False)

for i in range(10**N):
    num = str(i)
    if len(num) == 3:
        for j,l in enumerate(L):
            if num[l[0]-1] == str(l[1]):
                ans[j] = True 
                continue
            else:
                break
        if all(ans):
            print(i)
            break
if not all(ans):
  print(-1)