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

done = [-1 for _ in range(N)]

isExist = True

for m in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        isExist = False
    if done[N-s] == c:
        continue
    if done[N-s] != -1:
        isExist = False
    key += c * pow(10, N-s)
    done[N-s] = c

if isExist == True and 0 <= key:
    print(key)
else:
    print(-1)