package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	in := make(map[int]int, m)
	for i := 0; i < m; i++ {
		ind := 0
		val := 0
		fmt.Scan(&ind, &val)
		if ind == 1 && val == 0 {
			fmt.Println(-1)
		}
		if in[ind] != 0 && in[ind] != val {
			fmt.Println(-1)
			return
		}
		in[ind] = val
	}

	for i := 1; i < int(math.Pow(10, float64(n))); i++ {
		n := i
		ind := keta(n)
		for n != 0 {
			b := n % 10
			if b != in[ind] {
				break
			}
			if ind == 1 {
				fmt.Println(i)
				return
			}
			n /= 10
			ind--
		}
	}
}

func keta(i int) int {
	hoge := 0
	for i != 0 {
		i /= 10
		hoge++
	}
	return hoge
}