def get_ints():
    return list(map(int, input().split()))

n, m = get_ints()
digits = [-1 for i in range(n)]

for i in range(m):
    s, c = get_ints()
    s -= 1
    if digits[s] >= 0 and digits[s] != c:
        print(-1)
        exit(0)
    digits[s] = c

if digits[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit(0)

if digits[0] == -1:
    digits[0] = 1

print(''.join(map(lambda x: str(max(0, x)), digits)))
