N, M = map(int,input().split())
A = [0 for k in range(N)]
U = [-1 for k in range(N)]
for k in range(M):
    s, c = map(int,input().split())
    if U[s-1] != -1 and A[s-1] != c:
        print("-1")
        exit(0)
    else:
        A[s-1] = c
        U[s-1] = 1

if A[0] == 0 and len(A) > 1:
    print(-1)
else:
    print("".join(map(str,A)))
