package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	s := make([]int, M)
	c := make([]int, M)
	for i := 0; i < M; i++ {
		s[i], c[i] = ReadInt()-1, ReadInt()
	}

	low := 0
	if N >= 2 {
		low = 1
		for j := 0; j < N-1; j++ {
			low *= 10
		}
	}
	for i := low; i < low*10; i++ {
		str := strconv.Itoa(i)
		ok := true
		for j := 0; j < M; j++ {
			if str[s[j]]-'0' != byte(c[j]) {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(str)
			return
		}
	}
	fmt.Println(-1)
}

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
}
