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)

digit = max(s)

ans = []

if digit == 1:
    for i in range(10):
        num = str(i)
        flg = 0
        for j in range(m):
            if num[s[j] - 1] == str(c[j]):
                flg = 1
            else:
                flg = 0
                break
        if flg == 1:
            ans.append(i)
else:
    for i in range(10 ** (digit - 1), 10 ** digit):
        num = str(i)
        flg = 0
        for j in range(m):
            if num[s[j] - 1] == str(c[j]):
                flg = 1
            else:
                flg = 0
                break
        if flg == 1:
            ans.append(i)

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