N, M = (int(x) for x in input().split())
k = {}
j = True
ans = []

for i in range(M):
    a, b = input().split()
    a = int(a)
    ans.append("0")
    if a not in k.keys():
        k[a] = b
    else:
        if k[a] != b:
            j = False
            break

for n in range(N):
    if n + 1 in k.keys():
        ans[n] = k[n + 1]

if j:
    f = int("".join(ans))
    print(f)
else:
    print(-1)