N ,M = map(int,input().split())
cnt = [0]*N
C = [0]*N
C[0] = 1
for i in range(M):
    s, c = map(int,input().split())
    if cnt == 1 and C[s-1] != c:
        cnt[s-1] += 1
    elif cnt[s-1] == 1 and C[s-1] == c:
        pass
    else:
        cnt[s-1] += 1
        C[s-1] = c
if min(C) == 0 and max(C) ==0:
    print(0)
elif max(cnt)>=2 or C[0] == 0 :
    print(-1)
else:
    print("".join(map(str,C)))