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

sc = [list(map(int,input().split())) for i in range(M)]

ans = [0]*N
ans[0] = 1

pre_s = []

check = {}
for s,c in sc:
    if s in check:
        if c != check[s]:
            print(-1)
            exit()
    else:
        check[s] = c
    ans[s-1] = c

ans = int("".join(map(str,ans)))

if len(str(ans)) != N:
    print(-1)
    exit()

print(ans)
