package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

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

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	M := nextInt()
	s := make([]int, M)
	c := make([]int, M)
	for i := 0; i < M; i++ {
		s[i] = nextInt()
		c[i] = nextInt()
	}

	var start int
	if N == 1 {
		start = 1
	} else {
		start = int(math.Pow(10, float64(N-1)))
	}
	var no bool
	for i := start; i < int(math.Pow(10, float64(N))); i++ {
		no = false
		for j := 0; j < M; j++ {
			if s[j] == N {
				if c[j] == i%10 {
					continue
				} else {
					no = true
					break
				}
			} else {
				if c[j] == i/int(math.Pow(10, float64(N-s[j])))%10 {
					continue
				} else {
					no = true
					break
				}
			}
		}
		if !no {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}
