import sys
input = sys.stdin.readline
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

f = 1
d = [0 for i in range(n)]
for s, c in sc:
    s -= 1
    if s == 0 and c == 0 and n > 1:
        f = 0
        break
    if s > n-1:
        f = 0
        break
    if d[s] == 0:
        d[s] = c
    else:
        if d[s] != c:
            f = 0
            break

if f:
    print("".join([str(x) for x in d]))
else:
    print(-1)
