require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
S = []
C = []
M.times do |i|
  S[i], C[i] = get_ints
end

ans = '0' * N
ans[0] = '1'

hash = {}

M.times do |i|
  s = S[i] - 1
  if hash[s] && hash[s] != C[i]
    ans = -1
    break
  end
  hash[s] = C[i]
  ans[s] = C[i].to_s
end

if ans == -1
  puts ans
else
  if ans.to_i.to_s != ans
    puts -1
  else
    puts ans
  end
end

