package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func replace(slice []int, rep []int, start, end int) ([]int, error) {
	if len(slice) < start || len(slice) < end {
		return nil, fmt.Errorf("Error")
	}
	ans := make([]int, len(slice))
	copy(ans, slice)
	ans = append(ans[:start], rep...)
	ans = append(ans, slice[end:]...)
	return ans, nil
}

func main() {
	var s []int
	var c []int

	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()

	for i := 0; i < m; i++ {
		s = append(s, nextInt())
		c = append(c, nextInt())
	}

	// fmt.Printf("%v %v\n", n, m)
	// for i := 0; i < m; i++ {
	// 	fmt.Printf("%v %v\n", s[i], c[i])
	// }

	d := make(map[int]int)
	for i := 0; i < m; i++ {
		v, ok := d[s[i]]
		if ok && v != c[i] {
			// 既に指定桁に別の数値が入っているので不整合
			fmt.Println("-1")
			return
		}
		d[s[i]] = c[i]
	}
	// fmt.Printf("%v\n", d)

	result := make([]byte, n)
	for i := 0; i < n; i++ {
		result[i] = '0'
	}
	for k, v := range d {
		result[k-1] = '0' + byte(v)
	}
	for i := 0; i < n; {
		// fmt.Printf("%v\n", result)
		if len(result) == 0 {
			fmt.Println("-1")
			return
		}
		if result[i] == '0' {
			result = result[i+1:]
		} else {
			break
		}
	}

	fmt.Printf("%s\n", result)
}
