N, M = map(int, input().split())

def candidates():
    SC = [-1, -1, -1]
    correct = True
    for i in range(0, M):
        s, c = map(int, input().split())    
        if N > 1:
            if s == 1 and c == 0:
                correct = False
        if SC[s-1] == -1:
            SC[s-1] = c
        elif SC[s-1] != c:
            correct = False
    if correct:
        return SC
    else:
        return -1

sc = candidates()
if sc == -1:
    print(-1)
else:
    if M == 3:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        b = 0
        if sc[1] != -1:
            b = sc[1]
        c = 0
        if sc[2] != -1:
            c = sc[2]
        print(a * 100 + b * 10 + c)

    if M == 2:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        b = 0
        if sc[1] != -1:
            b = sc[1]
        print(a * 10 + b)

    if M == 1:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        print(a)