N, M = map(int,input().split())
coef = [0]*N
for i in range(M):
    si, ci = map(int, input().split())
    if si==1 and N>1 and ci==0:
        print(-1)
        exit()
    elif coef[si-1]==ci or coef[si-1]==0:
        coef[si-1] = ci
    else:
        print(-1)
        exit()

ans = 0
for j in range(N):
    ans += coef[j]*10**(N-j-1)

print(ans)