import sys

N, M = map(int, input().split())
U = 10 ** N
A = [[int(i) for i in input().split()] for _ in range(M)]

def check(s):
    for k, c in A:
        if k > len(s):
            return False
        if s[k - 1] != str(c):
            return False
    return True


for i in range(1, U):
    s = str(i)
    if check(s):
        print(i)
        sys.exit()
print(-1)
