from collections import defaultdict
b = list(map(int,input().split()))

s = [list(map(int,input().split())) for i in range(b[1])]
flag = 0
  
n=defaultdict(int)
for i in range(b[0]):
  n[i+1] = -1
for i in range(b[1]):
  if (s[i][0] == 1) & (s[i][1] == 0):
    flag = 1
    break
  elif (n[s[i][0]] != s[i][1]) & (n[s[i][0]] != -1):
    #print(n[s[i][0]],s[i][1])
    flag = 1
    break
  else:
    n[s[i][0]] = s[i][1]
  
total = 0
for key in n.keys():
  if n[key] != -1:
    total += n[key]*(10**(b[0]-key))
  
if flag == 1:
  print(-1)
else:
  print(total)