N, M = map(int, input().split())
S = []
C = []
for i in range(M):
    s, c = input().split()
    S.append(int(s))
    C.append(int(c))

A = [0]*N
for a, b in zip(S, C):
    if a == 1 and b == 0:
        if N != 1:
            print(-1)
            exit()
    if a == 2 and b == 0:
        if N != 3:
            print(-1)
            exit()
    A[a-1] = b

if N == 3 and A[0] == 0:
    A[0] = 1

if N == 2 and A[0] == 0:
    A[0] = 1
for a in A:
    print(a, end="")
