n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
s=sorted(s)
l = [0] * n
ans = []
ss = []
aaa = ""
for i in range(m):
    if aaa == s[i][0]:
        continue
    else:
        l[int(s[i][0]-1)]=s[i][1]
        aaa = s[i][0]
    ans.append(l)
for i in range(len(ans)):
    ss.append(int("".join(map(str, ans[i]))))


if len(str(min(ss)))!=n:
    print("-1")
else:
    print(min(ss))