n, m = map(int, input().split())
sc = [[0, 0]] * m
for i in range(m):
    sc[i][0], sc[i][1] = map(int, input().split())
sorted(sc)

def checker():
    if m == 0:
        if n == 1:
            return 0
        else:
            return -1
    for i in range(1, m):
        if sc[i - 1][0] == sc[i][0] and sc[i - 1][1] != sc[i][1]:
            return -1
    if n == 1:
        if sc[-1][0] == 1:
            return sc[0][1]
    elif n == 2:
        if sc[-1][0] == 1:
            return sc[0][1] * 10
        elif sc[0][0] == 2 and sc[-1][0] == 2:
            return 10 + sc[0][1]
        elif sc[0][0] == 1 and sc[-1][0] == 2:
            if sc[0][1] != 0:
                return sc[-1][1] + 10 * sc[0][1]
    elif n == 3:
        if sc[-1][0] == 1:
            return sc[0][1] * 100
        elif sc[-1][0] == 2:
            if sc[0][0] == 1:
                return 10 * sc[-1][0] + 100 * sc[0][1]
            else:
                return 100 + 10 * sc[-1][0]
        elif sc[-1][0] == 3:
            if sc[0][0] == 3:
                return 100 + sc[0][1]
            elif sc[0][0] == 2:
                return 100 + sc[-1][1] + 10 * sc[0][1]
            else:
                r1 = 0
                r2 = 0
                r3 = 0
                for i in range(m):
                    if sc[i][0] == 1:
                        r1 = sc[i][1]
                    elif sc[i][0] == 2:
                        r2 = sc[i][1]
                    elif sc[i][0] == 3:
                        r3 = sc[i][1]
                return 100 * r1 + 10 * r2 + r3
    return -1

print(checker())
