n,m = map(int, input().split())
sc = [ list(map(int,input().split())) for _ in range(m)]

ans = [0] * n
change_cnt = [0] * n
if n >= 2:
    ans[0]=1
for i in range(n):
    for j in range(m):
        if i+1 == sc[j][0]:
            if ans[i] != sc[j][1]:
                ans[i] = sc[j][1]
                change_cnt[i] += 1
                if change_cnt[i] > 1:
                    print(-1)
                    exit()

if n>=2:
    if ans[0]==0:
        print(-1)
        exti()

answer = ''
for i in range(len(ans)):
    answer += str(ans[i])

print(int(answer))
