x = input().split()
N = int(x[0])
M = int(x[1])

SC = [input().split() for i in range(M)]
s = [int(x[0]) for x in SC]
c = [int(x[1]) for x in SC]

T = 0
if N > 1:
    for i in range(M):
        if s[i] == 1 and c[i] == 0:
            T = -1
for i in range(M):
    for j in range(M):
        if (s[i] == s[j]) and (c[i] != c[j]):
            T = -1
if T == -1:
    print(-1)
else:
    L = [0 for i in range(N)]
    K ="No"
    for i in range(M):
        if s[i] == 1:
            K = "Yes"
    if K == "Yes":
        for i in range(N):
            for j in range(M):
                if i == s[j]-1:
                    L[i] = c[j]
    else:
        L[0] = 1
        for i in range(N):
            for j in range(M):
                if i == s[j]-1:
                    L[i] = c[j]
    s = ""
    for i in range(N):
        s = s + str(L[i])
    print(int(s))