package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	digits, m := nextInt(), nextInt()
	var num = make(map[int]int)
	for i := 0; i < m; i++ {
		digit, v := nextInt(), nextInt()
		if num[digit] == 0 || v < num[digit] {
			num[digit] = v
		}
	}
	var _digits int
	var ans int
	for k, v := range num {
		if _digits < k {
			_digits = k
		}
		// 107
		if k == 1 {
			ans += v * int(math.Pow(float64(10), float64((2))))
		} else if k == 2 {
			ans += v * int(math.Pow(float64(10), float64((1))))
		} else {
			ans += v
		}
	}
	if _digits == digits {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}
