
def main():
    N,M=map(int,input().split())
    L=[0]*N
    for i in range(M):
        s,c=map(int,input().split())
        if L[s-1] and L[s-1]!=c:
            return -1
        L[s-1]=c
    
    output=int(''.join(map(str,L)))
    if N==1:
        return output
    if output and len(str(output))==N:
        return output
    else:
        return -1
    
print(main())

