package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scan(&M, &N)
	d := []int{-1, -1, -1}
	out := false
	for N > 0 {
		N--
		var s, c int
		fmt.Scan(&s, &c)
		if out {
			continue
		}
		if d[M-s] >= 0 && d[M-s] != c {
			out = true
			continue
		}
		d[M-s] = c
	}
	if out || (M > 1 && d[M-1] == 0) {
		fmt.Println("-1")
	} else {
		ans := 0
		switch M {
		case 1:
			if d[0] == -1 {
				ans = 0
			} else {
				ans = d[0]
			}
		case 2:
			if d[0] == -1 {
				d[0] = 0
			}
			ans = d[1]*10 + d[0]
		case 3:
			if d[0] == -1 {
				d[0] = 0
			}
			if d[1] == -1 {
				d[1] = 0
			}
			ans = d[2]*100 + d[1]*10 + d[0]
		}

		fmt.Printf("%d\n", ans)
	}

}
