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

for i in range(10**4):
    if len(str(i))!=n:
        continue
    for j in range(m):
        if str(i)[sc[j][0]-1] == str(sc[j][1]):
            if j == m-1:
                print(i)
                exit()
        else:
            break
print(-1)