N, M = map(int, input().split())

d = {1:-1, 2:-1, 3:-1}

flag = True
for i in range(M):
    s, c = map(int, input().split())

    if N > 1 and s == 1 and c == 0:
        flag = False

    if d[s] == -1:
        d[s] = c

    elif d[s] == c:
        pass

    else:
        flag = False

for i in range(1, N+1):
    if d[i] == -1:

        if N == 1:
            d[i] = 0

        if N > 1 and i == 1:
            d[i] = 1

        else:
            d[i] = 0

inv_ans = 0
for i in range(1, N+1):
    inv_ans += int(d[i]) * 10 ** (i-1)

ans = str(inv_ans)[::-1]

print(ans) if flag else print(-1)