n, m = map(int, input().split())
num = [0] * n
cond = [list(map(int, input().split())) for _ in range(m)]

loop_cnt = 0

for i, j in cond:
    if loop_cnt == 0:
        num[i - 1] = j
    else:
        if num[i - 1] == j:
            continue
        elif num[i - 1] == 0:
            num[i - 1] = j
        else:
            print(-1)
            exit()
    loop_cnt += 1

val = int(''.join(list(map(str, num))))

if len(str(val)) == n:
    print(int(val))
else:
    print(-1)