n,m = map(int, input().split())
Flag = True
l = ["*"]*n
for i in range(m):
    s,c = map(int, input().split())
    if l[s-1]=="*" or l[s-1]==c:
        l[s-1] = c
    else:
        Flag = False
l = "".join(map(str,l))
l = l.replace("*","0")
if len(l) >= 2 and l[0] == "0":
    Flag = False
print(l if Flag else -1)