N,M=map(int,input().split())
s=[list(map(int,input().split())) for i in range(M)]

A=['inf']*N
#print(A)
def main():
    for i in range(M):
        if A[s[i][0]-1]=='inf':
            A[s[i][0]-1]=s[i][1]
        else:
            if A[s[i][0]-1]==s[i][1]:
                continue
            else:
                return -1
                break

    for j in range(N):
        A[j]=str(A[j])
        if A[j]=='inf':
            A[j]='0'
    if len(str(int(''.join(A))))==N:
        return ''.join(A)
    else:
        return -1
    
print(main())
            
