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

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



L = [-1] * N



for s, c in sc:

  s -= 1

  if L[s] == -1:

    L[s] = c

  else:

    if L[s] != c:

      print((-1))

      exit()



if N == 1:

  if L[0] == -1:

    print((0))

  else:

    print((L[0]))

else:

  if L[0] == 0:

    print((-1))

    exit()

  if L[0] == -1:

    ans = 1

  else:

    ans = L[0]

  for i in range(1, N):

    ans *= 10

    if L[i] != -1:

      ans += L[i]

  print(ans)

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

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



t = 10 ** (N - 1)

e = t * 10

if N == 1:

  t = 0



for i in range(t, e):

  k = list(str(i))

  for s, c in sc:

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

      break

  else:

    print(i)

    exit()

print((-1))

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
L = [-1] * N
for s, c in sc:
    s -= 1
    if L[s] == -1:
        L[s] = c
    else:
        if L[s] != c:
            print((-1))
            exit()
if N == 1:
    if L[0] == -1:
        print((0))
    else:
        print((L[0]))
else:
    if L[0] == 0:
        print((-1))
        exit()
    if L[0] == -1:
        ans = 1
    else:
        ans = L[0]
    for i in range(1, N):
        ans *= 10
        if L[i] != -1:
            ans += L[i]
    print(ans)

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
t = 10 ** (N - 1)
e = t * 10
if N == 1:
    t = 0
for i in range(t, e):
    k = list(str(i))
    for s, c in sc:
        if int(k[s - 1]) != c:
            break
    else:
        print(i)
        exit()
print((-1))

-L = [-1] * N -for s, c in sc: -    s -= 1 -    if L[s] == -1: -        L[s] = c +t = 10 ** (N - 1) +e = t * 10 +if N == 1: +    t = 0 +for i in range(t, e): +    k = list(str(i)) +    for s, c in sc: +        if int(k[s - 1]) != c: +            break -        if L[s] != c: -            print((-1)) -            exit() -if N == 1: -    if L[0] == -1: -        print((0)) -    else: -        print((L[0])) -else: -    if L[0] == 0: -        print((-1)) +        print(i) -    if L[0] == -1: -        ans = 1 -    else: -        ans = L[0] -    for i in range(1, N): -        ans *= 10 -        if L[i] != -1: -            ans += L[i] -    print(ans) +print((-1))