N,M = map(int,input().split())
ans = [0] * N
sc = []
for i in range(M):
    s,c = map(int,input().split())
    sc.append((s,c))
sc = sorted(sc,reverse=True)
#print(sc)
for s,c in sc:
    ans[s-1] = c
if N != 1 and ans[0] == 0:
    print(-1)
else:
    print("".join([str(i) for i in ans]))
