N, M = map(int, input().split())
s = []
c = []
for _ in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)
N_list = [10,]*(N)

f = True
for i in range(M):
    if N_list[s[i]-1] == 10:
        N_list[s[i]-1] = c[i]
    if N_list[s[i]-1] != c[i]:
        f = False
        print('-1')
        break
if f:
    if N == 1:
        if N_list[0] == 10 or N_list[0] == 0:
            print(0)
        else:
            print(N_list[0])
    else:
        if N_list[0] == 10:
            N_list[0] == 1
        elif N_list[0] == 0:
            print('-1')
        else:
            N_list = [N_list[i]%10 for i in range(N)]
            count = 0
            for i, n in enumerate(list(range(N))[::-1]):
                count += N_list[i] * 10**n
            print(count)