package main

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

var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}

func init() {
	nextReader = newScanner()
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

func main() {
	N, M := nextInt(), nextInt()
	s := make([]int, M, M)
	c := make([]int, M, M)
	digits := make(map[int]int)
	for i := 1; i <= N; i++ {
		digits[i] = -1
	}
	for i := 0; i < M; i++ {
		s[i], c[i] = nextInt(), nextInt()
		if digits[s[i]] != c[i] && digits[s[i]] != -1 {
			fmt.Println(-1)
			return
		}
		digits[s[i]] = c[i]
	}
	if digits[1] <= 0 && len(digits) != 1 {
		fmt.Println(-1)
		return
	}
	var sum int
	for i := 1; i <= N; i++ {
		v := digits[i]
		if v == -1 {
			v = 0
		}
		sum += v * pow(10, N-i)
	}
	if sum == -1 {
		fmt.Println(0)
	} else {
		fmt.Println(sum)
	}
}
