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



pattern = ["."] * N

for i in range(M):

  s,c = input().split()

  s = int(s)

  if pattern[s - 1] not in (".",c):

    print((-1))

    exit(0)

  pattern[s - 1] = c



import re



comp = re.compile("^" + "".join(pattern) + "$")



for i in range(1001):

  res = comp.match(str(i))

  if res:

    print(i)

    break

else:

  print((-1))

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



if N == 1:

  ans = ["0"]

  default = "0"

else:

  ans = ["1"] + ["0"] * (N - 1)

  default = "1" + "0" * (N - 1)



for i in range(M):

  s,c = input().split()

  s = int(s) - 1

  if N > 1 and s == 0 and c == "0":

    print((-1))

    exit(0)

  if ans[s] == default[s] or ans[s] == c:

    ans[s] = c

  else:

    print((-1))

    exit(0)

     

print(("".join(ans)))
N, M = list(map(int, input().split()))
pattern = ["."] * N
for i in range(M):
    s, c = input().split()
    s = int(s)
    if pattern[s - 1] not in (".", c):
        print((-1))
        exit(0)
    pattern[s - 1] = c
import re

comp = re.compile("^" + "".join(pattern) + "$")
for i in range(1001):
    res = comp.match(str(i))
    if res:
        print(i)
        break
else:
    print((-1))

N, M = list(map(int, input().split()))
if N == 1:
    ans = ["0"]
    default = "0"
else:
    ans = ["1"] + ["0"] * (N - 1)
    default = "1" + "0" * (N - 1)
for i in range(M):
    s, c = input().split()
    s = int(s) - 1
    if N > 1 and s == 0 and c == "0":
        print((-1))
        exit(0)
    if ans[s] == default[s] or ans[s] == c:
        ans[s] = c
    else:
        print((-1))
        exit(0)
print(("".join(ans)))

-pattern = ["."] * N +if N == 1: +    ans = ["0"] +    default = "0" +else: +    ans = ["1"] + ["0"] * (N - 1) +    default = "1" + "0" * (N - 1) -    s = int(s) -    if pattern[s - 1] not in (".", c): +    s = int(s) - 1 +    if N > 1 and s == 0 and c == "0": -    pattern[s - 1] = c -import re - -comp = re.compile("^" + "".join(pattern) + "$") -for i in range(1001): -    res = comp.match(str(i)) -    if res: -        print(i) -        break -else: -    print((-1)) +    if ans[s] == default[s] or ans[s] == c: +        ans[s] = c +    else: +        print((-1)) +        exit(0) +print(("".join(ans)))