n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
st = 0 if n==1 else 10**(n-1)
en = 10**n
for x in range(st,en):
    xs = str(x)
    for i in range(m):
        if int(xs[sc[i][0]-1]) != sc[i][1]:
            break
    else:
        print(x)
        break
else:
    print(-1)