n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]

for a,b in li:
    if n == 1 and b == 0:
        print(0)
        exit()
ans_li = []
for i in range(10**(n-1),10**n):
    p = list(map(int,list(str(i))))
    for s,c in li:
        if p[s-1] != c:break
    else:
        ans_li.append(i)
if not ans_li:
    print(-1)
else:
    print(min(ans_li))