n,m = map(int, input().split())
a = [input() for _ in range(m)]
b = set(a)
c = [list(map(int, ai.split())) for ai in a]
d = dict(c)

if len(d) != len(b):
    print(-1)
else:
    if n == 1:
        print(d[0])
    else:
        if d[0] == 0:
            print(-1)
        else:
            ans = ["0"] * n
            for k in d:
                ans[k-1] = str(d[k])
            print("".join(ans))
