import sys

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

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

if num[0] == -1 or num[0] == 0:
    print(-1)
    sys.exit()

for i in range(N):
    if num[i] == -1:
        num[i] = 0
print("".join(map(str, num)))