N,M = list(map(int, input().split()))

appeard_digit = {}
ans = 0
sc_pair = []
max_digit = -1
for _ in range(M):
    s,c = list(map(int, input().split()))

    sc_pair.append([s,c])
    if max_digit < s:
        max_digit = s

if max_digit > N:
    print(-1)
    exit()

for s,c in sc_pair:
    if s == 1 and c == 0 and max_digit>1:
        print(-1)
        exit()
    if s not in appeard_digit:
        ans += c * 10**(max_digit-s)
        appeard_digit[s] = c
    elif s in appeard_digit and appeard_digit[s] != c:
        print(-1)
        exit()
if max_digit < N:
    print(str(ans)+"0"*(N-max_digit))
else:
    print(ans)
