# 2020/05/05
# AtCoder Beginner Contest 157 - C

# Input - Line1
n, m = map(int,input().split())
sclist = list()

for i in range(m):
    sc = list(map(int,input().split()))
    sclist.append(sc)
    
sclist.sort()

savs = -1
savc = -1
ans = -2
keta = [-1] * 4
for i in range(m):
    # 2桁以上で1桁目がゼロのケースを-1
    if n > 1 and sclist[i][1] == 0 and sclist[i][0] < 3 - (3-n) and savs == -1:
        ans = -1
        break

    # 同じ桁に対して異なる値の場合は-1
    if savs == sclist[i][0] and savc != sclist[i][1]:
        ans = -1
        break
    savs = sclist[i][0]
    savc = sclist[i][1]
    keta[sclist[i][0]] = sclist[i][1]

strval = ''
if ans != -1:
    for i in range(1, 4-(3-n)):
        if keta[i] == -1:
            strval = strval + '0'
        else:
            strval = strval + str(keta[i])
    ans = int(strval)

# Output
print(ans)
