N, M = map(int,input().split())
A=[set() for _ in range(N)]
for _ in range(M):
    s, c = map(int,input().split())
    A[s-1].add(c)

ans = 0
for i in range(N):
    L = list(A[i])
    if len(L) >= 2:
        print(-1)
        exit()
    if len(L) == 1 and N != 0 and L[0] == 0 and i == 0:
        print(-1)
        exit()
    if len(L) == 1:
        a = L[0]
    elif len(L) == 0:
        if i == 0:
            a = 1
        else:
            a = 0
    ans = 10*ans+a

print(ans)