n, m = map(int, input().split())
lisn = [list(map(int, input().split())) for i in range(m)]
lisa = []
lisb = []
flug = 0
for i in range(m):
    lisa.append(0)
for j in range(m):
    if lisn[j][0] in lisb:
        flug = 1
    lisb.append(lisn[j][0])
    lisa[lisn[j][0] - 1] = lisn[j][1]
if flug == 1 or (lisa[0] == 0 and n != 0):
    print(-1)
else:
    print(''.join(map(str, lisa)))