package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type pair struct {
	s int
	c int
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := readInt(), readInt()

	pairs := make(map[int]int, 0)
	for i := 0; i < m; i++ {
		s := readInt()
		c := readInt()
		if _, ok := pairs[s-1]; ok {
			if pairs[s-1] != c {
				fmt.Println("-1")
				return
			}
		}
		pairs[s-1] = c
	}
	for i := 1; i <= 999; i++ {
		ok := true
		keta := 0
		k := i
		r := make([]int, 0)
		for k > 0 {
			r = append(r, k%10)
			k /= 10
			keta++
		}
		if keta != n {
			ok = false
			continue
		}
		Reverse(r)
		for k, v := range r {
			if _, exist := pairs[k]; !exist {
				continue
			}
			if pairs[k] != v {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("-1")
}

func Reverse(a []int) []int {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}
