package main

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

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	
	s := make(map[int]int, m)
	
	tmpk, tmpv := 0, 0
	for i := 0; i < m; i++ {
		fmt.Scan(&tmpk,&tmpv)
		if s[tmpk] != 0 && s[tmpk] != tmpv {
			fmt.Println(-1)
			return
		} else {
			s[tmpk] = tmpv
		}
	}
	//fmt.Println(s)
	
	ans := make([]string, n)
	
	for i := 0; i < n; i++{
		if s[i+1] == 0 {
			ans[i] = "0"
		} else {
			ans[i] = strconv.Itoa(s[i+1])
		}
	}
	
	if ans[0] == "0" {
		fmt.Println(-1)
		return
	}
	
	fmt.Println(strings.Join(ans,""))
}