n, m = [int(i) for i in input().split()]
a = [10] * n
for i in range(m):
    s, c = [int(i) for i in input().split()]
    s -= 1
    a[s] = min(c, a[s])

if a[0] == 10 or n >= 2 and a[0] == 0:
    print("-1")
else:
    ans = ""
    for i in a:
        if i == 10:
            ans += "0"
        else:
            ans += str(i)
    print(ans)
