import sys

N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
if (max(s) == 1) and (N == 1):
  for x in range (0,10):
    ans = 1
    x1 = str(x)
    for i in range (0,M):
      if (x1[s[i]-1] != str(c[i])) :
        ans = 0
        break
    if (ans == 1):
      print(x)
      sys.exit()
    
for x in range (10 ** (max(s)-1) ,10 ** N):
  ans = 1
  x1 = str(x)
  for i in range (0,M):
    if (x1[s[i]-1] != str(c[i])) :
      ans = 0
      break
  if (ans == 1):
    print(x)
    sys.exit()
print(-1)