n,m = map(int,input().split())
ketasuu,content = [],[]
for _ in range(m):
    s,c = map(int,input().split())
    ketasuu.append(s-1)
    content.append(c)
ans = 10000-1
for i in range(0,10000):
    tmp =list(str(i)) 
    flag = []
    for j in range(m):
        try:
            if tmp[ketasuu[j]] == str(content[j]):
                flag.append(True)
            else:
                flag.append(False)
        except:
            pass
    if all(flag) and len(tmp)==n:
        ans = min(i,ans)
if ans == 10000:
    print(-1)
else:
    print(ans)