N, M = map(int, input().split())

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

ans = [[] for _ in range(M)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in ans:
    if len(set(i)) > 1:
        print(-1)
        exit()
    if len(i) == 0:
        ans2.append(0)
        continue
    ans2.append(list(set(i))[0])

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

print(''.join(map(str,ans2)))
    