N, M = map(int, input().split())
l = list(range(N))
for i in range(N):
    l[i-1] = 0

ans = 0
for j in range(M):
    s, c = input().split()
    s = int(s)
    if l[s-1] == 0:
        l[s-1] = c
    elif l[s-1] != 0 and l[s-1] != c:
        ans = -1
        break

if ans != -1:
    ans = [str(a) for a in l]
    ans = "".join(ans)
    if int(ans) == 0:
        ans = -1

print(ans)
