N, M = map(int, input().split())
if M == 0:
    print(10**(N-1))
    exit(0)
A = [[] for i in range(0, N)]
for i in range(0, M):
    x, y = map(int, input().split())
    if not(y in A[x-1]):
        A[x-1].append(y)
for a in A:
    if len(a) > 1:
        print(-1)
        exit(0)
ans = ''
if 0 in A[0]:
    print(-1)
    exit(0)
for i in range(0, N):
    if len(A[i]) == 1:
        ans += str(A[i][0])
    else:
        if i == 0:
            ans += '1'
        else:
            ans += '0'
print(ans)
