import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
D = [-1] * N

for m in range(M):
    s, c = [int(x) for x in input().strip().split()]
    if D[s-1] == -1:
        D[s-1] = c
        continue
    if D[s-1] == c:
        continue
    print(-1)
    exit()

if N > 1:
    if D[0] == 0:
        print(-1)
        exit()
    for n in range(1, N):
        if D[n] == -1:
            D[n] = 0

print(D)
ans = ''
for i in range(N):
    ans += str(D[i])

print(int(ans))
