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

for i in range(M):
    for j in range(M):
        if i == j:
            break
        elif s[i] == s[j] and c[i] != c[j]:
            print(-1)
            exit()

for i in range(M):
    if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()

num = [0]*N

if N == 1:
    if M > 0:
        print(c[0])
    else:
        print(0)

elif N == 2:
    for i in range(M):
        if s[i] == 1 and c[i] == 0:
            print(-1)
            exit()
    for i in range(M):
        num[s[i]-1] = c[i]
    if num[0] == 0:
        print("1"+str(num[1]))
    else:
        print(str(num[0])+str(num[1]))

else:
    top_f = 0
    sec_f = 0

    for i in range(M):
        if s[i] == 1 and c[i] == 0:
            top_f = 1
        elif s[i] == 2 and c[i] == 0:
            sec_f = 1
    if top_f == 1 and sec_f == 1:
        print(-1)
        exit()
    for i in range(M):
        num[s[i]-1] = c[i]
    if num[0] == 0:
        print("1"+str(num[1])+str(num[2]))
    else:
        print(str(num[0])+str(num[1])+str(num[2]))
