package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	n, m := scanInt(), scanInt()
	digit := make([]int, m)
	val := make([]string, m)
	for i := 0; i < m; i++ {
		digit[i] = scanInt() - 1
		val[i] = scanText()
	}

	for i := 1; i <= 999; i++ {
		ans := strconv.Itoa(i)
		if n != len(ans) {
			continue
		}

		ok := true
		for j := 0; j < m; j++ {
			d := digit[j]
			if ans[d] != val[j][0] {
				ok = false
				break
			}
		}

		if ok {
			fmt.Print(ans)
			return
		}
	}

	fmt.Print(-1)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[0] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}
