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

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



for i in range(10000):

  st = str(i)

  if len(st) != n:

    continue

  ok = True

  for s,c in req:

    if int(st[s-1]) != int(c):

      ok = False

  if ok:

    print(st)

    exit()

    

print((-1))
N,M = list(map(int,input().split()))

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



for i in range(10**N):

  if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):

    print(i)

    break

    

else:

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

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for m in range(M)]
for i in range(10**N):
    if len(str(i)) == N and all(str(i)[s - 1] == str(c) for s, c in sc):
        print(i)
        break
else:
    print((-1))

-n, m = list(map(int, input().split())) -req = [list(map(int, input().split())) for i in range(m)] -for i in range(10000): -    st = str(i) -    if len(st) != n: -        continue -    ok = True -    for s, c in req: -        if int(st[s - 1]) != int(c): -            ok = False -    if ok: -        print(st) -        exit() -print((-1)) +N, M = list(map(int, input().split())) +sc = [list(map(int, input().split())) for m in range(M)] +for i in range(10**N): +    if len(str(i)) == N and all(str(i)[s - 1] == str(c) for s, c in sc): +        print(i) +        break +else: +    print((-1))