n, m = gets.chomp.split(' ').map(&:to_i)

def guess_num(n, m)
  num = Array.new(n, 0)
  m.times do
    s, c = gets.chomp.split(' ').map(&:to_i)
    return print(-1) if num[s-1] != 0 && num[s-1] != c
    num[s-1] = c
  end
  return print(-1) if num.size > 1 && (num = num.join('').to_i) == 0
  print(num)
end

guess_num(n, m)
