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

for s, c in sc:
    if s in l and ans[s-1] != c:
        print("-1")
        exit()
    ans[s-1] = c
    l.append(s)

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

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