N,M = list(map(int,input().split()))
S = []
C = []
ans = [0 for i in range(3)]
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] or ans[S[i]-1] == 0:
        ans[S[i]-1] = C[i]
    else:
        fr += 1
if fr != 0:
    print(-1)
else:
    print(ans[0]*100 + ans[1]*10 + ans[2])