N, M = map(int, input().split())
ans = -1
S = [0] * M
C = [0] * M
for i in range(M):
    S[i], C[i] = map(int, input().split())

def check(x):
    if len(str(x)) != N:
        return False
    for s, c in zip(S, C):
        if str(x)[s-1] != str(c):
            return False    
    return True

for i in range(1,10**N):
    if check(i):
        ans = i
        break

print(ans)