import strutils, sequtils, math, algorithm, tables

# let
#     # 文字列
#     s = stdin.readLine

#     # 単一数値
#     n = stdin.readLine.parseInt

#     # 数列
#     a = stdin.readLine.split.map(parseInt)

# 複数の数値の分割代入
var
    N, M: int
(N, M) = stdin.readLine.split.map(parseInt)

var table = initTable[int, int]()

for i in 0..<M:
    var
        s1, c1: int
    (s1, c1) = stdin.readLine.split.map(parseInt)
    if not table.hasKey(s1):
        table.add(s1, c1)
    else:
        table[s1] = min(table[s1], c1)


if(N == 1):
    for i in 0..9:
        if(i == table[1]):
            echo i
            quit()
    echo "-1"
    quit()

if(N == 2):
    for i in 10..99:
        if(not table.hasKey(2)):
            table.add(2, 0)
        if(not table.hasKey(1)):
            table.add(1, 0)
        if table[1] != 0 and i div 10 == table[1] and
                i mod 10 == table[2]:
            echo i
            quit()
    echo "-1"
    quit()

if(N == 3):
    if(not table.hasKey(3)):
        table.add(3, 0)
    if(not table.hasKey(2)):
        table.add(2, 0)
    if(not table.hasKey(1)):
        table.add(1, 0)
    for i in 100..999:
        if(table[1] != 0 and i div 100 == table[1] and (
                i mod 100) div 10 == table[2] and (i mod 10) == table[3]):
            echo i
            quit()
    echo "-1"
    quit()

