import sys
n, m = map(int, input().split())
r = [-1] * n

for _ in range(m):
    s, c = map(int, input().split())
    if r[s-1] == -1 or r[s-1] == c:
        r[s-1] = c
    else:
        print(-1)
        sys.exit(0)

if r[0] == 0:
    print(-1)
    sys.exit(0)
if r[0] == -1 and n >= 2:
    r[0] = 1

n_r = [0 if i == -1 else i for i in r]
result = ''.join([str(i) for i in n_r])
print(result)