package main

import (
	"fmt"
	"math"
	"strconv"
)

func solution(n, m int, nums [][]int) int {
	tmp := make([]int, n)
	for i := 0; i < m; i++ {
		tmp[nums[i][0]-1] = nums[i][1]
	}
	var max int
	for i := 0; i < n; i++ {
		max += int(math.Pow10(2-i)) * tmp[i]
	}

	ans := 1 << 31
	for i := max; i > 0; i-- {
		if isDigitCondition(n, i) && isCondition(nums, m, i) {
			ans = min(ans, i)
		}
	}
	if ans != 1<<31 {
		return ans
	}
	return -1
}

func isCondition(nums [][]int, m, num int) bool {

	s := strconv.Itoa(num)
	for i := 0; i < m; i++ {
		for j, v := range s {
			if j == nums[i][0]-1 && int(v)-48 != nums[i][1] {
				return false
			}
		}
	}
	return true
}

func isDigitCondition(n, num int) bool {
	var c int
	var d int = num
	for d > 0 {
		d /= 10
		c++
	}
	if c == n {
		return true
	}
	return false
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var n, m, s, c int
	fmt.Scan(&n, &m)
	nums := make([][]int, m)
	for i := range nums {
		nums[i] = make([]int, 2)
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&s, &c)
		nums[i][0] = s
		nums[i][1] = c
	}

	fmt.Println(solution(n, m, nums))
}
