[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, 4):
    if i not in dic:
        dic[i] = 0

if N == 1:
    if dic[1] != 'x':
        print(-1)
    else:
        print(dic[1])
else:
    if dic[1] == 0 or ('x' in dic.values()):
        print(-1)
    else:
        if N == 2:
            print(10*dic[1] + dic[2])
        else:
            print(100*dic[1] + 10*dic[2] + dic[3])