N , M = [int(i) for i in input().split()]
s  = [[int(j) for j in input().split()] for i in range(M)]
#print(s)
#print(c)
x = 0
#for i in range(N):
s = list(map(list, set(map(tuple, s))))
f = [0] * N

#print(f)
for ss in s:
    if f[ss[0]-1] == 1:
        x = -1
        break
    if ss[0] == 1 and ss[1]==0:
        if N == 1:
            x = 0
            break
        else:
            x = -1
            break
        
    f[ss[0]-1] = 1
    x += ss[1] * 10 ** (N-ss[0])
    #for cc in c:

if x < 10 ** N:
    print(-1)
else:
    print(x)

