import sys
n, m = map(int, input().split())
check = [list(map(int, input().split())) for i in range(m)]

for i in range(1, 1000):
    x = str(i)
    if len(x) != n:
        continue
    flg = True
    for s, c in check:
        if x[s-1] == str(c):
            pass
        else:
            flg = False
    if flg:
        print(i)
        sys.exit()
print(-1)