import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    NLIST = []
    for i in range(M):
        NLIST.append(list(map(int, lines.pop(0).split(' '))))

    n = 0
    for digit,c in NLIST:
        x = (10 ** (N - digit))
        a = c * x

        if digit == 1:
            ch = n // 100
        elif digit == 2:
            ch = n % 100
            ch = ch // 10
        elif digit == 3:
            ch = n % 100
            ch = ch % 10

        if N != 1 and digit == 1 and c == 0:
            n = -1
            break

        if n == 0 or ch == 0:
            n += a
        elif ch == c:
            continue
        elif ch != c:
            print(-1)
            return


    if N == 1 and n <= 10 and n >= 0:
        print(n)
    elif 10 ** (N-1) > n:
        print(10**(N-1)+n)
    else:
        print(n)

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)