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

a_list = [0] * N

uncorrect = 0
changezero = True

for i in range(M):
    s,c = map(int, input().split())
    if s == 1:
        zero == False 
    if a_list[s-1] == 0:
        a_list[s-1] += c
    else:
        if a_list[s-1] != c:
            uncorrect += 1

if changezero and N >= 2:
    a_list[0] += 1

if uncorrect >= 1:
    print(-1)
elif a_list[0] == 0 and N >= 2:
    print(-1)
else:
    ans = 0
    for i in range(N):
        ans += a_list[i] * (10 ** (N-i-1))

    print(ans)