n,m = list(map(int,input().split()))

sc = [list(map(int,input().split())) for i in range(m)]



for i in range(10000):

    s = str(i)

    if len(s) != n:

        continue

    ok = True

    for a, b in sc:

        if s[a - 1] != str(b):

            ok = False

            break

    if ok:

        print(i)

        exit()



print((-1))

n,m = list(map(int,input().split()))

sc = [list(map(int,input().split())) for _ in range(m)]



for i in range(1000):

    s = str(i)

    if len(s) != n: continue

    if all(s[a - 1] == str(b) for a, b in sc):

        print(i)

        exit()



print((-1))

n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(m)]
for i in range(10000):
    s = str(i)
    if len(s) != n:
        continue
    ok = True
    for a, b in sc:
        if s[a - 1] != str(b):
            ok = False
            break
    if ok:
        print(i)
        exit()
print((-1))

n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    s = str(i)
    if len(s) != n:
        continue
    if all(s[a - 1] == str(b) for a, b in sc):
        print(i)
        exit()
print((-1))

-sc = [list(map(int, input().split())) for i in range(m)] -for i in range(10000): +sc = [list(map(int, input().split())) for _ in range(m)] +for i in range(1000): -    ok = True -    for a, b in sc: -        if s[a - 1] != str(b): -            ok = False -            break -    if ok: +    if all(s[a - 1] == str(b) for a, b in sc):