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 y in A[x-1]:
        continue
    A[x-1].append(y)
for a in A:
    if len(a) > 1:
        print(-1)
        exit(0)
ans = ''
if A[0][0] == 0:
    print(-1)
    exit(0)
for i in range(0, N):
    if len(A[i]) == 1:
        ans += str(A[i][0])
    else:
        ans += '0'
print(ans)
