N, M = map(int, input().split())
list_sc = []
for _ in range(M):
    s, c = map(int, input().split())
    list_sc.append([s, c])

num = [-1] * (M + 1)
numint = 0
for i in range(M):
    if num[list_sc[i][0]] == -1:
        num[list_sc[i][0]] = list_sc[i][1]
    elif num[list_sc[i][0]] == list_sc[i][1]:
        pass
    else:
        numint = -1

if numint == -1:
    pass
else:
    numint = 0
    for i in range(1, M + 1):
        numint *= 10
        if num[i] == -1:
            pass
        else:
            numint += num[i]

print(numint)