n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

if n == 1:
    start = 0
    end = 10
elif n == 2:
    start = 10
    end = 100
else:
    start = 100
    end = 1000

ans = []

for i in range(start, end):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j] - 1] == str(c[j]) and len(num) == n:
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)