from collections import Counter

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

sc = [[0,0] for _ in range(M)]
X = [0 for _ in range(N)]

for i in range(M):
    sc[i][0],sc[i][1] = map(int,input().split())
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

sc = get_unique_list(sc)



sc_0 = [0 for _ in range(len(sc))]
judge = True

for i in range(len(sc)):
    sc_0[i]= sc[i][0]

cnt_sc0 = Counter(sc_0)
for i in sc_0:
    if cnt_sc0[i]> 1:
        judge = False
        break
    
for i in range(len(sc)):
    X[sc[i][0]-1] = sc[i][1]

for i in range(len(X)):
    if X[i] >= 1:
        x = X[i:]
        break

if len(x)==N and judge==True:
    print(int("".join(map(str,x))))
else:
    print(-1)
