def main():
    n,m=map(int,input().split())
    sc=[list(map(int,input().split())) for _ in range(m)]
    a=[0]*(n+1)
    if n==3:
        a[1]=1
    elif n==2:
        a[2]=1
    d=[-1]*(n+1)
    for i in range(m):
        s=sc[i][0]
        c=sc[i][1]
        if d[s]==-1 or a[s]==c:
            a[s]=c
            d[s]=0
        else:
            print(-1)
            return
    ans=100*a[1]+10*a[2]+a[3]
    if ans>=10**(n-1):
        print(ans)
        return
    else:
        print(-1)
        return
main()