package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	nums := make([]int, n)
	isUsed := make(map[int]bool, n)
	var s, c int
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d", &s, &c)
		if nums[s-1] == 0 || nums[s-1] == c {
			if isUsed[s-1] && nums[s-1] != c {
				fmt.Println("-1")
				return
			}
			nums[s-1] = c
			isUsed[s-1] = true
		} else {
			fmt.Println("-1")
			return
		}
	}
	if n == 2 && m == 0 {
		fmt.Println("10")
		return
	}
	if n == 3 && m == 0 {
		fmt.Println("100")
		return
	}
	if n > 2 && nums[0] == 0 {
		fmt.Println("-1")
		return
	}
	for i := 0; i < n; i++ {
		fmt.Print(nums[i])
	}
}
