n,m = map(int,input().split())
query = [list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    k = str(i)
    flag = True
    for s,c in query:
        if k[s-1] != str(c):
            flag = False
    if flag and len(k) == n:
        print(i)
        exit()
print(-1)