package main

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

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

// nの上位d桁目の数
func digitNum(n, d int) int {
	s := strconv.Itoa(n)
	return int(s[d-1] - '0')
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	s, c := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		s[i], c[i] = nextInt(), nextInt()
	}

	ans := -1
	iMax := pow(10, n)
	for i := pow(10, n-1); i < iMax; i++ {
		ok := true
		for j := 0; j < m; j++ {
			if digitNum(i, s[j]) != c[j] {
				ok = false
				break
			}
		}
		if ok {
			ans = i
			break
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}
