[N, M] = [int(i) for i in input().split()]
dic = {}
for i in range(M):
    [s, c] = [int(i) for i in input().split()]
    if s in dic:
        if dic[s] != c:
            dic[s] = 'x'
    else:
        dic[s] = c
for i in range(1, N+1):
    if i in dic:
        continue
    else:
        dic[i] = 0 

ans = 0
if N == 1:
    if dic[1] == 'x':
        print(-1)
    else:
        print(dic[1])
else:
    t = 0
    for key in dic:
        if dic[key] == 'x':
            t += 1
    if t == 0 and dic[1] != 0:
        for key in dic:
            ans += dic[key]*10**(N-key)
        print(ans)
    else:
        print(-1)