N,M = list(map(int,input().split()))
S = []
C = []
ans = [11 for i in range(N)]
fr = 0
for i in range(M):
    s = 0
    c = 0
    s,c = list(map(int,input().split()))
    S.append(s)
    C.append(c)

for i in range(M):
    if C[i] != ans[S[i]-1] and ans[S[i]-1] != 11:
        fr = 1
    elif C[i] == 0 and S[i] == 1:
        fr = 1
    else:
        ans[S[i]-1] = C[i]

for i in range(N):
    if ans[i] == 11:
        ans[i] = 0

if ans[0] == 0 and N > 1:
    ans[0] = 1

if fr != 0:
    print(-1)
else:
    if N == 3:
        print(ans[0]*100 + ans[1]*10 + ans[2])
    elif N == 2:
        print(ans[0]*10 + ans[1])
    else:
        print(ans[0])