def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, M = getInput()
ret = [int(0) for i in range(N+1)]
ret[1] = 99
flg = False

for i in range(M):
    S, C = getInput()
    if ret[S] == 99:
        ret[S] = C
        continue
    elif not ret[S] == 0:
        if ret[S] == C:
            continue
        else:
            flg = True
    ret[S] = C

ret.pop(0)
if ret[0] == 99:
    ret[0] = 1
if ret[0] == 0:
    flg = True
print('-1') if flg else print(''.join([str(i) for i in ret]))