n,m = map(int,input().split())
t = [[] for _ in range(n)]
for i in range(m):
    t_1,t_2 = map(int,input().split())
    t[t_1-1].append(t_2)

ans = ""
for i in t:
    if len(set(i)) == 1:
        ans += str(i[0])
    if not i:
        ans += "0"
if ans[0] == "0":
    print(-1)
else:
    print(ans)
