n, m = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(m)]

NUM = [0] * n
for s, c in SC:
    if n != 1:
        if s == n-1 and c == 0:
            print(-1)
            exit()

    if NUM[n - s] == 0:
        NUM[n - s] = c
    elif (NUM[n - s] != 0) and (NUM[n - s] != c):
        print(-1)
        exit()
if n != 1 and NUM[n - 1] == 0:
    print(-1)
    exit()

for s in NUM[::-1]:
    print(s, end="")
