package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()

	c := make([]int, n)
	for i := 0; i < n; i++ {
		c[i] = -1
	}
	for i := 0; i < m; i++ {
		s := scanInt()-1
		num := scanInt()

		if c[s] == -1 {
			c[s] = num
		} else {
			if c[s] != num {
				fmt.Fprintln(wr, -1)
				return
			}
		}
	}

	chk := 0
	for i := 0; i < n; i++ {
		if chk == 0 && c[i] == 0 {
			if i == n-1 {
				break
			}
			fmt.Fprintln(wr, -1)
			return
		}
		chk++
	}
	
	if n==1 {
		if c[0] == -1 {
			c[0] = 0
		}
		fmt.Fprintln(wr, c[0])
		return
	}

	d := 1
	for i := 0; i < n; i++ {
		d *= 10
	}


	for i := d/10; i < d; i++ {
		num := i
		f := true
		for j := 0; j < n; j++ {
			if c[n-1-j] == -1 {
				num /= 10
				continue
			}

			if c[n-1-j] != num%10 {
				f = false
			}
			num /= 10
		}

		if f {
			fmt.Fprintln(wr, i)
			return
		}
		fmt.Fprintln(wr, i)
	}

	fmt.Fprintln(wr, -1)
	
}
