N,M = map(int, input().split())
s1 = []
s2 = []
flg = True
for i in range(M):
  n1,n2 = map(int,input().split())
  s1.append(n1)
  s2.append(n2)
for i in range(1000):
  flg = True
  num = [int(x) for x in list(str(i))]
  if len(num) == N:
    for j in range(M):
      if s2[j] != num[s1[j] - 1]:
        flg = False
    if flg:
      print(i)
      exit()
if flg == False:
  print(-1)