N, M = map(int, input().split())
s, c = [], []
for i in range(M):
    S, C = map(int, input().split())
    s.append(S)
    c.append(C)

for i in range(M):
    for j in range(M):
        if i == j:
            break
        elif s[i] == s[j] and c[i] != c[j]:
            print(-1)
            exit()

num = [0]*N
for i in range(M):
    num[s[i]-1] = c[i]
if num[0] == 0:
    print(-1)
else:
    for i in num:
        print(i, end="")
    print("")
