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

# 辞書初期化3桁0埋め
dic = {}
for i in range(N):
    dic[i] = 0

# scの辞書化
dic2= {}
for i in sc:
    if (i[0]-1 not in dic2.keys()) or (i[0]-1 in dic2.keys()) and (i[1] <= dic2[i[0]-1]):
        dic2[i[0]-1] = i[1]
# update
dic.update(dic2)

s = ''
for k,v in dic.items():
    s += str(v)

if len(str(int(s))) == N:
    print(int(s))
else:
    print(-1)