package main

import (
        "fmt"
)

func solution(n, m int, matrix [][]int) int {
        var ans int = 1000
        memo := make(map[int]int, n)

        for i := range matrix {
                memo[matrix[i][0]] = matrix[i][1]
        }

        for i := 0; i < 1000; i++ {
                s := fmt.Sprint(i)
                if n != len(s) {
                        continue
                }
                if m == 0 {
                        ans = min(ans, i)
                        continue
                }
                if isCond(s, memo) {
                        ans = min(ans, i)
                }
        }
        if ans == 1000 {
                return -1
        }
        return ans
}
func isCond(s string, memo map[int]int) bool {
        for i, num := range s {
                // log.Printf("s: %v, memo: %v, i: %v, n: %v, s: %v", s, memo, i, int(n), string(num))
                if memo[i+1] != int(num)-48 {
                        return false
                }
        }
        return true
}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        matrix := make([][]int, m)

        for i := 0; i < m; i++ {
                var s, c int
                fmt.Scan(&s, &c)
                matrix[i] = []int{s, c}
        }
        fmt.Println(solution(n, m, matrix))
}