N,M= map(int,input().split())
R = []
for _ in range(M):
    R.append(tuple(input().split()))
for n in range(10**(N-1), 10**N):
    isa = True
    for (s,c) in R:
        if str(n)[int(s)-1] != c:
            isa = False
    if isa:
        print(n)
        exit()
print(-1)