N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

while len(ans) > 0:
    if ans[0] == -1:
        ans = ans[1:]
    else:
        break

if ans == [-1]:
    print(-1)
    exit()

ans = [a if a != -1 else 0 for a in ans]
print(''.join(list(map(str, ans))))