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

ans = 1000
for num in range(10 ** (n - 1), 10 ** n):
    st = str(num)
    bl = True
    for s, c in sc:
        s -= 1
        if st[s] != str(c):
            bl = False

    if bl:
        ans = min(ans, num)

if ans == 1000:
    ans = -1

print(ans)
