N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

conditions = [-1] * N

ans = 0
for s, c in sc:
    if conditions[s - 1] == -1:
        conditions[s - 1] = c
    else:
        if c == conditions[s - 1]:
            pass
        else:
            ans = -1
            break
if N >= 2 and conditions[0] == 0:
    ans = -1

if ans == 0:
    ans = ""
    for cnd in conditions:
        if cnd == -1:
            ans += "0"
        else:
            ans += str(cnd)

print(ans)
