def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

n,m = map(int,input().split())
sc = list(list(map(int,input().split())) for _ in range(m))

sc = get_unique_list(sc)
ans = 0
s = set()
flag = True
for i in range(len(sc)):
    s.add(sc[i][1])
s = list(s)
    
for i in range(len(sc)):
    if min(s) == 0:
        flag = False

for i in range(len(sc)-1):
    for j in range(1,len(sc)):
        if sc[i][0] == sc[j][0] and sc[i][0] != sc[j][1]:
            flag = False

if flag:
    for i in range(len(sc)):
        ans += 10**(n-sc[i][0])*sc[i][1]
        
print(ans if flag else "-1")