N, M = list(map(int, input().split()))
SC = []
for i in range(M):
    s, c = list(map(int, input().split()))
    SC.append([s-1, c])

poss = []
if N == 3:
    s = 100
    e = 1000
elif N == 2:
    s = 10
    e = 100
else:
    s = 1
    e = 10

for i in range(s, e):
    poss.append(str(i))

for s, c in SC:
    poss2 = []
    for n in poss:
        if n[s] == str(c):
            poss2.append(n)
    poss = poss2

# print(poss2)

if poss:
    print(poss[0])
else:
    print(-1)