n, m = gets.split.map(&:to_i)
sc = Array.new(m){gets.split.map(&:to_i)}
ans = '*' * n
sc.each do |s, c|
  if ans[s-1] == '*'
    ans[s-1] = c.to_s 
  elsif ans[s-1] != c.to_s
    ans[s-1] = 'X'
  end
end
ans.gsub!('*', '0')
p ans
if ans.include?('X')
  puts '-1'
elsif ans.start_with?('0') && n > 1
  puts '-1'
else
  puts ans
end
