#n = int(input())
n,m = map(int,input().split())
#a_L = list(map(int,input().split()))
s_L,c_L = [],[]

for _ in range(m):
    s,c = map(int,input().split())
    s_L.append(s-1)
    c_L.append(c)

ans = 10000
for i in range(700,703):
    tmp =list(str(i)) 
    #i = list(str(i))
    #print(tmp)
    flag = []
    for j in range(m):
        
        try:
            if tmp[s_L[j]] == str(c_L[j]):
                flag.append(True)
            else:
                #print(tmp)
                flag.append(False)
        except:
            pass
    if all(flag) and len(tmp)==n:
        #print("OK")
        #print(i)
        ans = min(i,ans)

if ans == 10000:
    print(-1)
else:
    print(ans)