n, m = map(int, input().split())

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

ans = [0] * n

check = [0] * n

if m == 0 and n > 1:
    ans[0] = 1
    s = list(map(str, ans))
    print("".join(s))
    exit()

for i in range(m):
    if check[-li[i][0]] == 0:
        ans[-li[i][0]] = li[i][1]
        check[-li[i][0]] = 1
    else:
        if ans[-li[i][0]] == li[i][1]:
            continue
        else:
            print(-1)
            exit()

if ans[-1] == 0 and n != 1:
    print(-1)
    exit()

res = []
for i in range(n):
    res.append(str(ans[-i-1]))
    
print("".join(res))