N,M=map(int,input().split())
nums={}
for i in range(M):
    s,c=map(str,input().split())
    if s in nums.keys():
        if nums[s]!=c:
            ans=-1
            print(ans)
            exit()
    else:
        nums[s]=c
for i in range(1,N+1):
    if str(i) not in nums.keys():
        nums[str(i)]='0' if i!=1 else '1'
n=[]
for i in sorted(nums):
    n.append(nums[i])
ans=int(''.join(n))
if len(list(str(ans)))!=N:
    ans=-1
print(ans)