import sys
n, m = map(int, input().split())
d = [10] * n
for _ in range(m):
    s, c = map(int, input().split())
    s = s - 1
    if d[s] == 10:
        d[s] = c
    elif d[s] != c:
        print(-1)
        sys.exit()
if d[0] == 0:
    print(-1)
    sys.exit()
if d[0] == 10:
    d[0] == 1
for i in d:
    print(0, end='') if i == 10 else print(i, end='')