n,m = gets.split(" ").map(&:to_i)
a = Array.new(n, nil)
b = 0
m.times do
  s,c = gets.split(" ").map(&:to_i)
  if a[s-1] == nil
    a[s-1] = c
  elsif a[s-1] == c
  else
    b = 1
  end
end

if b == 1
  print(-1)
else
  if a.map(&:to_i)[0] == 0
    print(-1)
  else
    print(a.map(&:to_i).join())
  end
end