package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	m := nextInt()
	s := make([]int, m)
	c := make([]int, m)

	for i := 0; i < m; i++ {
		s[i] = nextInt()
		c[i] = nextInt()
	}

	start := pow(10, n-1)
	for i := start; i < start*10; i++ {
		ok := true
		nn := fmt.Sprintf("%d", i)
		for j := 0; j < m; j++ {
			//fmt.Println("CMP: ,", string(nn[s[j]-1]), " vs c[", j, "]=", c[j])
			if nn[s[j]-1]-'0' != byte(c[j]) {
				ok = false
			}
		}
		if ok == true {
			fmt.Println(i)
			return
		}
	}

	fmt.Println("-1")

}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
