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

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

i = 10**(N-1) if N > 1 else 0

while i < 10**N:

  n = [(i//10**j)%10  for j in reversed(list(range(N)))]

  f = True

  for s, c in SC:

    if n[s-1] != c:

      f = False

  if f:

    break

  i += 1

if i >= 10**N:

  print((-1))

else:

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

num = [-1]*N

err = False

for _ in range(M):

  s, c = list(map(int, input().split()))

  if num[s-1] == -1:

    num[s-1] = c

  else:

    if num[s-1] != c:

      err = True

if err or (N > 1 and num[0] == 0):

  print((-1))

else:

  ans = 0

  i = 0

  n = 0

  while i < N:

    if num[i] < 0:

      n = 1 if i == 0 and N > 1 else 0

    else:

      n = num[i]

    ans = ans * 10 + n

    i += 1

  print(ans)
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
i = 10 ** (N - 1) if N > 1 else 0
while i < 10**N:
    n = [(i // 10**j) % 10 for j in reversed(list(range(N)))]
    f = True
    for s, c in SC:
        if n[s - 1] != c:
            f = False
    if f:
        break
    i += 1
if i >= 10**N:
    print((-1))
else:
    print(i)

N, M = list(map(int, input().split()))
num = [-1] * N
err = False
for _ in range(M):
    s, c = list(map(int, input().split()))
    if num[s - 1] == -1:
        num[s - 1] = c
    else:
        if num[s - 1] != c:
            err = True
if err or (N > 1 and num[0] == 0):
    print((-1))
else:
    ans = 0
    i = 0
    n = 0
    while i < N:
        if num[i] < 0:
            n = 1 if i == 0 and N > 1 else 0
        else:
            n = num[i]
        ans = ans * 10 + n
        i += 1
    print(ans)

-SC = [list(map(int, input().split())) for _ in range(M)] -i = 10 ** (N - 1) if N > 1 else 0 -while i < 10**N: -    n = [(i // 10**j) % 10 for j in reversed(list(range(N)))] -    f = True -    for s, c in SC: -        if n[s - 1] != c: -            f = False -    if f: -        break -    i += 1 -if i >= 10**N: +num = [-1] * N +err = False +for _ in range(M): +    s, c = list(map(int, input().split())) +    if num[s - 1] == -1: +        num[s - 1] = c +    else: +        if num[s - 1] != c: +            err = True +if err or (N > 1 and num[0] == 0): -    print(i) +    ans = 0 +    i = 0 +    n = 0 +    while i < N: +        if num[i] < 0: +            n = 1 if i == 0 and N > 1 else 0 +        else: +            n = num[i] +        ans = ans * 10 + n +        i += 1 +    print(ans)