#!/usr/bin/env python3

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