def main():

    N,M=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(M)]
    cal=0
    ans=[0]*N
    end,ct=0,0
    for i in range(M):
        cal=(a[i][0]-1)
        if ans[cal]!=0:
            ans[cal]=min(ans[cal],a[i][1])
        else:
            ans[cal]=a[i][1]

    for i in range(N):
        if ans[i]==0:
            ct+=1

    if ans[0]==0:
        print(-1)
        return

    elif ct==N:
        print(0)
        return

    end="".join(map(str,ans))
    print(end)
    return

main()
