n,m = map(int,input().split())


def judge():
    ans="-"*n
    for i in range(m):
        s,c = map(int,input().split())
        if (s-1)==0 and c==0:
            if n==1:
                return 0
            else:
                return -1
        elif ans[s-1]!="-" and int(ans[s-1])!=c:
            return -1
        else:
            a = list(ans)
            a[s-1] = str(c)
            ans = "".join(a)
    ans=ans.replace("-","0")
    return ans

print(judge())