#nは桁数　 (1,0)が含まれてる時と、(2,4),(2,7)みたいな入力の時はだめ
n,m = map(int,input().split())
s = [0]*m
c = [0]*m
d = dict()
ans = 0

for x in range(m):
    s[x],c[x] = map(int,input().split())
    if s[x] not in d:
        d[s[x]] = c[x]
    elif d[s[x]] != c[x]:
        ans = -1
        break

else:
    ans = ""
    for x in range(1,n+1):
        if x in d :
            if x != 1:
                ans += str(d[x])
            elif x == 1 and d[x] != 0:
                ans += str(d[x])
            elif n == 1 and d[x] == 0:
                ans += "0"
            else:
                ans = -1
                break
        else:
            if x == 1:
                ans += str(1)
            else:
                ans += str(0)

print(ans)
