N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

for i in range(10**N):
    n = str(i)
    length = len(n)
    
    for s, c in sc:
        if length < s: break
        if n[s-1] != str(c): break
    else:
        n = int(n)
        if n == 0: continue
        print(n)
        break
    
else: print(-1)