N, M = map(int, input().split())

S = []
C = []

condition = [-1] * M

for _ in range(M):
    s, c = map(int, input().split())
    #S.append(s)
    #C.append(C)
    if condition[s-1] != c and condition[s-1] != -1:
        print('-1')
        exit()
    condition[s-1] = c

for i, v in enumerate(condition):
    if v == -1:
        condition[i] = 0
    print(condition[i], end="")
