#--------------------------------------------------
import strutils, sequtils, math, algorithm, tables, sets, lists, intsets, critbits, future
proc readSeq(): seq[string] =
    stdin.readLine.split
proc readSeqInt(): seq[int] =
    stdin.readLine.split.map(parseInt)
proc readInt1(): int =
    stdin.readLine.parseInt
proc readInt2(): (int, int) =
    let a = readSeq().map(parseInt)
    return (a[0], a[1])
proc readInt3(): (int, int, int) =
    let a = readSeq().map(parseInt)
    return (a[0], a[1], a[2])
proc readInt4(): (int, int, int, int) =
    let a = readSeq().map(parseInt)
    return (a[0], a[1], a[2], a[3])
#--------------------------------------------------
var (n,m) = readInt2()
var s,c = newseq[int]()
for i in 1..m:
    var t = readSeqInt()
    s.add(t[0])
    c.add(t[1])
    if t[0]>n:
        echo -1
        quit(QuitSuccess)

var ans = -1
for i in 0..999:
    if ($i).len==n:
        var t = true
        for j in 0..m-1:
            if (i div (10^(3 - s[j]))) mod 10 != c[j]:
                t = false
                break
        if t:
            ans = i
            break

echo ans