N,M = input().split()
N = int(N)
M = int(M)
ans = ["-" for _ in range(N)]
p = []
for _ in range(M):
   p.append(input().split())

def check(i,p):
    i = str(i)
    for pp in p:
        if i[int(pp[0])-1] != pp[1]:
 
            return False
    return True

# pには条件がある
c = False
for i in range(10**(N-1),10**N):
    if check(i,p):
        c = True
        break
if c:
    print(i)
else:
    print(-1)