package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	m := make(map[int]int)
	for i := 0; i < M; i++ {
		s, c := ReadInt(), ReadInt()
		if prev, exists := m[s-1]; exists && prev != c {
			fmt.Println(-1)
			return
		}
		m[s-1] = c
	}

	base := 1
	for i := 0; i < N-1; i++ {
		base *= 10
	}
	ans := 0
	leftSet := false
	for i := 0; i < N; i++ {
		if c, exists := m[i]; exists {
			if c == 0 && !leftSet && i < N-1 {
				fmt.Println(-1)
				return
			}
			ans += base * c
			leftSet = true
		}
		base /= 10
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
