n, m = map(int, input().split())
sc = []
ans = [[] for i in range(n)]
res = [0] * n
f = True
for i in range(m):
    s, c = map(int, input().split())
    sc.append([s, c])

l = sorted(sc)
l.reverse()

for i in range(m):
    ans[l[i][0]-1].append(l[i][1])
    res[l[i][0]-1] = l[i][1]
f = True
cnt = 0
for i in range(m):
    cnt += 1
    if i == 0 and len(ans[0]) == 0:
        f = False
        break
    for j in range(1, len(ans[i])-1):
        if ans[i][j-1] != ans[i][j]:
            f = False
            break
    else:
        continue
    break

    res[l[i][0]-1] = l[i][1]

if f and cnt == n:
    print("".join(map(str, res)))
else:
    print('-1')