package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func gcd(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return gcd(a%b, b)
	}
}

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

func min(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func nextByte() byte {
	sc.Scan()
	s := sc.Bytes()
	return s[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	N := nextInt()
	M := nextInt()
	var s [5]int
	var c [5]byte
	for i := 0; i < M; i++ {
		s[i] = nextInt()
		c[i] = nextByte()
	}
	ans := -1
	mn := 1
	mx := 10
	ok := true
	for i := 0; i < N-1; i++ {
		mn *= 10
		mx *= 10
	}
	for i := mn; i < mx; i++ {
		num := strconv.Itoa(i)
		ok = true
		for j := 0; j < M; j++ {
			if num[s[j]-1] != c[j] {
				ok = false
			}
		}
		if ok == true {
			ans = i
			break
		}
	}
	//ans := int64(math.Ceil(float64(N)/float64(minnum)) + 4)
	fmt.Printf("%d\n", ans)
}
