N, M = map(int, input().split())
A = [[0] 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) > 2:
        print(-1)
        exit(0)
ans = ''
for i in range(0, N):
    if len(A[i]) == 2:
        ans += str(A[i][-1])
    else:
        ans += str(A[i][0])
print(ans)
