from collections import defaultdict

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

for _ in range(M):
    s, c = map(int, input().split())
    
    if s==1 and c==0:
        print(-1)
        exit()
        
    if s in d:
        if c!=d[s]:
            print(-1)
            exit()
    else:
        d[s] = c

ans = ''

for i in range(1, N+1):
    if i in d:
        ans += str(d[i])
    else:
        ans += '0'

print(ans)