import math

N, M = map(int, input().split())
num = [-1] * N

if M == 0:
    print(0)
    exit()

for _ in range(M):
    s, c = map(int, input().split())
    if num[s - 1] != -1 and num[s - 1] != c:
        print(-1)
        exit()
    num[s - 1] = c

ans = 0

for i in range(N):
    if num[i] == -1:
        if i == 0:
            if N == 1:
                num[i] = 0
            else:
                num[i] = 1
        else:
            num[i] = 0
    ans += int(num[i] * math.pow(10, N - i - 1))

if len(str(ans)) != N:
    print(-1)
else:
    print(ans)