(n,_),*t=[t.split()for t in open(0)]

n=int(n)

for i in range(10**(n-1)-(n<2),10**n):

  i=str(i)

  for s,c in t:

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

      break

  else:

    print(i)

    break

else:

  print((-1))
(n,_),*z=[t.split()for t in open(0)]

n=int(n)

a=0

for i in range(1000):

  t=str(i)

  a|=n==-~a*len(t)and all(c==t[int(s)-1]for s,c in z)and-~i

print((a-1))
(n, _), *t = [t.split() for t in open(0)]
n = int(n)
for i in range(10 ** (n - 1) - (n < 2), 10**n):
    i = str(i)
    for s, c in t:
        if i[int(s) - 1] != c:
            break
    else:
        print(i)
        break
else:
    print((-1))

(n, _), *z = [t.split() for t in open(0)]
n = int(n)
a = 0
for i in range(1000):
    t = str(i)
    a |= n == -~a * len(t) and all(c == t[int(s) - 1] for s, c in z) and -~i
print((a - 1))

-(n, _), *t = [t.split() for t in open(0)] +(n, _), *z = [t.split() for t in open(0)] -for i in range(10 ** (n - 1) - (n < 2), 10**n): -    i = str(i) -    for s, c in t: -        if i[int(s) - 1] != c: -            break -    else: -        print(i) -        break -else: -    print((-1)) +a = 0 +for i in range(1000): +    t = str(i) +    a |= n == -~a * len(t) and all(c == t[int(s) - 1] for s, c in z) and -~i +print((a - 1))