import sys
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    s=[0]*m
    c=[0]*m
    for i in range(m):
        s[i],c[i]=map(int,input().split())
    ans=[-1]*n
    A=0
    flg=0
    for i in range(m):
        if ans[s[i]-1]==-1:
            ans[s[i]-1]=c[i]
        elif ans[s[i]-1]!=c[i]:
            flg=1
            break
    if flg==1:
        print(-1)
    else:
        if ans[0]==0:
            print(-1)
        else:
            for i in range(n):
                if ans[i]==-1:
                    if i==0:
                        ans[i]=1
                    else:
                        ans[i]=0
                A=A*10+ans[i]
            print(A)

if __name__ == '__main__':
    main()