n, m = list(map(int, input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

ss = ["0"] * (n)
mask = ss.copy()
flag = True
for s, c in sc:
  
  if ss[s-1] == "0" or ss[s-1] == str(c):
    ss[s-1] = str(c)
  else:
    flag = False
    break
    
print("".join(ss) if flag and int("".join(ss)) > 0  else -1)