def calc():
    n, m = map(int, input().split())
    x = -1
    y = -1
    z = -1
    for i in range(0, m):
        s, c = map(int, input().split())
        if s == 1:
            if x == -1:
                x = c
            elif x != c:
                return -1
        elif s == 2:
            if y == -1:
                y = c
            elif y != c:
                return -1
        else:
            if z == -1:
                z = c
            elif z != c:
                return -1
    x = max(x, 0)
    y = max(y, 0)
    z = max(z, 0)
    res = x * 100 + y * 10 + z
    if n != len(str(res)):
        return -1
    return res


print(calc())
