N,M = map(int,input().split())
s_c = []
s = []
c = []
for i in range(M):
    s_c.append(list(map(int,input().split())))
    s.append(s_c[i][0])
    c.append(s_c[i][1])
if min(s) != 1 or M == 0:
    print(-1)
elif min(s) == 1 and M != 0:
    ans = []
    for i in range(M):
        if i + 1 in s:
            r = s.index(i + 1)
            ans.append(c[r])
        else:
            ans.append(0)
    if ans[0] == 0 and N == 1:
        print(-1)
    else:
        print(int("".join(map(str,ans))))
