import sys

N, M = [int(x) for x in input().split()]
gmin = 10 ** (N - 1)
gmax = 10 ** N - 1
check = []
print(str(gmin) + ',' + str(gmax))

def numCheck(i, check):
  for j in check:
    s, c = j.split()
    t = int(s) - 1
    if int(str(i)[t]) == int(c):
      continue
    else:
      return False
  return True


for i in range(M):
  check.append(input())

for i in range(gmin, gmax):
  if numCheck(i, check):
    print(i)
    sys.exit()
  else:
    continue
print(-1)
   
      