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

SCS = []
for _ in range(0, M):
    s, c = map(int, input().split())
    SCS.append((s, c))

def candidates():
    SC = [-1, -1, -1]
    for (s, c) in SCS:
        if N > 1:
            if s == 1 and c == 0:
                return -1
        if SC[s-1] == -1:
            SC[s-1] = c
        elif SC[s-1] != c:
            return -1
    return SC

sc = candidates()
if sc == -1:
    print(-1)
else:
    if N == 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 N == 2:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        b = 0
        if sc[1] != -1:
            b = sc[1]
        print(a * 10 + b)

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