n,m = map(int,input().split())
sc_inputs = [[int(j) for j in input().split()] for i in range(m)]

dic={}
for sc in sc_inputs:
    s,c = map(int,sc)
    if s in dic:
        if dic.get(s)!=c:
            print(-1);exit()
    dic[s]=c

if 1 in dic:
    if dic[1]==0:
        print(-1);exit()

ans=float('inf')
for i in range(10**(n-1),10**n):
    s = str(i)
    flag = True
    for key,value in dic.items():
        if s[key-1]!=str(value):
            flag=False
    if flag:
        ans=min(ans,int(s))
print(ans)
    


