n, m = map(int, input().split())
r = pow(10, n-1)
S = []
C = []
for i in range(m):
    s, c = map(int, input().split())
    if s in S:
        if C[S.index(s)] != c:
            r = -1
            break
    if s==1 and c==0:
        r = -1
        break
    else:
        S.append(s)
        C.append(c)
        if s==1:
            r += (c-1)*pow(10, n-s)
        else:
            r += c*pow(10, n-s)
print(r)