package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	N, M := readInt(), readInt()

	S, Max := map[int]int{}, 0
	for i := 0; i < M; i++ {
		key, value := readInt(), readInt()
		if v, exists := S[key]; exists && v != value {
			fmt.Println("-1")
			return
		}

		Max = max(key, Max)

		S[key] = value
	}

	Result := ""
	for i := 1; i <= max(Max, N); i++ {
		if v, exists := S[i]; exists {
			Result += strconv.Itoa(v)
		} else {
			if i == 1 {
				Result += "1"
			} else {
				Result += "0"
			}
		}
	}

	nr, f := "", false
	for _, c := range strings.Split(Result, "") {
		if c != "0" || f {
			f = true
			nr += c
		}

		if c == "0" && !f {
			continue
		}
	}

	Result = nr

	if len(Result) != N {
		fmt.Println("-1")
		return
	}

	fmt.Println(Result)
}

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

func max(a ...int) int {
	result := 0

	for _, i := range a {
		if result < i {
			result = i
		}
	}

	return result
}
