package main

import (
	"fmt"
	"strconv"
	"unicode/utf8"
)

func main() {
	N, M := readInt(), readInt()
	sc := make(map[int]int)

	for i := 0; i < M; i++ {
		s, c := readInt(), readInt()

		v, ok := sc[s]
		if ok && v != c {
			fmt.Println(-1)
			return
		}

		sc[s] = c
	}

	answer := ""
	for i := 0; i < N; i++ {
		v, ok := sc[i+1]
		if ok {
			answer += strconv.Itoa(v)
		} else {
			answer += "0"
		}
	}

	v, _ := strconv.Atoi(answer)
	vstr := strconv.Itoa(v)

	if utf8.RuneCountInString(vstr) != N {
		fmt.Println(-1)
		return
	}

	fmt.Println(v)
}

func readInt() int {
	var v int
	fmt.Scan(&v)
	return v
}
