
from collections import defaultdict
N, M = map(int, input().split())
SC = []
S = defaultdict(int)
for i in range(M):
    s, c = map(int, input().split())
    if S[s] > 0 and S[s] != c:
        print('-1')
        exit()
    if N > 1:
        if s == 1 and c == 0:
            print('-1')
            exit()
    S[s] = c

ans = ''
for i in range(1, N+1):
    if S[i]:
        ans += str(S[i])
    else:
        ans += '0'
print(ans)
