n, m = map(int, input().split())
ans = [0] * n
ok = True
check = [False] * n
for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    if check[s]:
        if ans[s] != c: ok = False
    else:
        ans[s] = c
    check[s] = True
if ok:
    Ans = 0
    for i in range(n):
        Ans = Ans * 10 + ans[i]
    print(Ans)
else:
    print(-1)