import math

N, M = map(int,input().split())

s = list()
c = list()
for i in range(M):
    s_val, c_val = map(int, input().split())
    s.append(s_val)
    c.append(c_val)

ans = 1000
for i in range(int(10**(N)-1), int(10**(N-1)-1),-1):
    keta=list()
    for j in range(N):
        keta.append((math.floor(i/(10**j))%10))
    counter = 0
    for k in range(M):
        
        if keta[N-s[k]] == c[k]:
            counter += 1
        if counter == M:
            ans = i
if ans == 1000:
    print(-1)
else:
    print(ans)