N,M = map(int,input().split())
sc = {}
flag = False
for i in range(M):
    s,c = map(int,input().split())
    if s==1 and c == 0:
        flag =True
        break
    elif s not in sc:
        sc[s] = c
    else:
        if sc[s] != c:
            flag = True
            break
if flag:
    print(-1)
elif N == 1 and M == 0:
    print(0)
else:
    if N == 1:
        print(sc[1])
    else:
        ans = [0 for i in range(N)]
        ans[0] = 1

        for s,c in sc.items():
            ans[s-1] = c
        print(*ans,sep='')
        print()
