n,m = map(int,input().split())

ls = [None]*n

p = True

for _ in range(m):
  s,c = input().split()
  s = int(s)-1
  
  if ls[s] is None:
    ls[s] = c
  elif not (ls[s]==c):
    p = False
    break


if p:
  ans = "" 
  for i in range(n):
    if i == 0 and ls[i] is None:
      ans += "1"
    elif ls[i] == None:
      ans+="0"
    else:
      ans += ls[i]
else:
  ans = -1
print(-1 if int(ans)==0 else ans)