package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, m := scanInt(), scanInt()
	xs := make([]int, n)
	for i := range xs {
		xs[i] = -1
	}

	for i := 0; i < m; i++ {
		s, c := scanInt(), scanInt()
		if xs[s-1] != -1 && xs[s-1] != c {
			fmt.Println(-1)
			return
		}
		xs[s-1] = c
	}

	ans := ""
	for i := range xs {
		if xs[i] == -1 {
			ans = ans + "0"
		} else {
			ans = ans + strconv.Itoa(xs[i])
		}
	}
	zero := true
	for i := n - 1; i >= 0; i-- {
		if ans[i] != '0' {
			zero = false
		} else if zero {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}
