import sys

N, M = map(int, input().split())
num_map = [None for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s > N or (num_map[s] is not None and num_map[s] != c) or (s == 0 and c == 0 and N > 1):
        print(-1)
        sys.exit()
    num_map[s] = c
num_map.reverse()

ans = 0
for i, num in enumerate(num_map):
    if num is not None:
        ans += num*(10**i)
print(ans)
