n, m = map(int,input().split())
clist=[-1]*n
ng=0

for i in range(m):
    s, c = map(int,input().split())
    if clist[s-1]==-1:
        clist[s-1]=c
    elif clist[s-1]!=c:
        ng=1

if ng==1:
    print(-1)
else:
    if clist[0]==0:
        print(-1)
    else:
        for i in range(n):
            if clist[i]==-1:
                print(0, end="")
            else:
                print(clist[i], end="")