def main():
    N,M=map(int,input().split())
    s=[list(map(int,input().split())) for _ in range(M)]
    cal=[0]*N
    ans=0
    for i in range(M):
        if s[i][0]>N or s[i][0]==0 or (s[i][0]==s[i-1][0] and s[i][1]!=s[i-1][1]):
            print("-1")
            return

        cal[s[i][0]-1]=s[i][1]

    if cal[0]==0:
        print("-1")
        return
        
    ans="".join(str(n) for n in cal)
    print(ans)
    return

main()
