N, M = map(int, input().split())
d = dict()
for o in range(1,N+1):
    d[o] = 1
S = []
C = []
for i in range(M):
    s, c = map(int,input().split())
    S.append(s)
    C.append(c)
    d[s] = c
if (1, 0) in d.items() and N != 1:
    print(-1)
    exit()
for j in range(0,M-1):
    for k in range(j+1, M):
        if S[j] == S[k] and C[j] != C[k]:
            print(-1)
            exit()
num = 0
for p in range(1,N+1):
    num += d[p]*10**(N-p)
print(num)