from sys import exit

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

ans = [0]*N
mask = [0]*N
for i in range(M):
    s,c = S[i],C[i]
    if mask[s-1]==0:
        mask[s-1] = 1
        ans[s-1] = c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit()

f = True
for i in range(N):
    if ans[i] != 0:
        f=False
if f:
    print(-1)
    exit()

t = False
k = []
for i in range(N):
    if f==False and ans[i] !=0:
        f = True
    if f:
        k.append(ans[i])
print(*k,sep='')