N, M = map(int,input().split())
A=[]
for _ in range(M):
    s, c = map(int,input().split())
    A.append([s,c])

ans = -1
for i in range(10**N):
    f=len(str(int(i)))==N
    for s, c in A:
        if c != (i // (10**(N-s))) % 10:
            f = False
    if f:
        ans = i
        break

print(ans)