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

l = [-1]*(n+1)

for _ in range(m):
  s,c = map(int,input().split())
  if l[s] == -1:
    l[s] = c
  else:
    if l[s] != c:
      print(-1)
      exit()

for i in range(1,n+1):
  if l[i] == -1:
    l[i] = 0
ls = list(map(str,l))
print(int(''.join(ls[1:])))