n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))

isExist = True
ans = [99] * n

for i in range(m):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] != 99 and ans[s] != c:
        isExist = False
        break
    else:
        ans[s] = c

ans = [0 if i == 99 else i for i in ans]

if sum(ans) == 0:
    isExist = False
else:
    ans = ''.join(list(map(str, ans)))

print(ans) if isExist else print(-1)
