n, m = map(int, input().split())
a = {}

for i in range(m):
    s, m = map(int, input().split())
    if s in a and a[s] != m:
        print(-1)
        exit(0)
    a[s] = m

if 1 in a and a[1] == 0:
    if n == 1:
        print(0)
        exit(0)
    else:
        print(-1)
        exit(0)

ans = ""
for i in range(1, n + 1):
    if i in a:
        ans += str(a[i])
    else:
        if i == 1:
            ans += "1"
        else:
            ans += "0"

if n >= 2 and ans[0] == "0":
    print(-1)
    exit(0)

print(int(ans))


