import sys
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


n,m  = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
length = len(l)
d = {}
for i in l:
    if i[0] in d and d[i[0]] != i[0]:
        d[i[0]] += 1
        break
    else:
        d[i[0]] =1
for j in d.values():
    if j != 1:
        print("-1")
        sys.exit()

l = get_unique_list(l)
l.sort()
d = 0
if l[0][1]==0 and l[0][0]==1:
    if n ==1:
        print("0")
        sys.exit()
    else:
        print("-1")
        sys.exit()
if l[0][0]!=1:
    d = 10**(n-1)
    for i in l:
        d += int(i[1])*10**(n-int(i[0]))
        
else:
    for i in l:
        d += int(i[1])*10**(n-int(i[0]))
print(d)