
n, m = map(int, input().split())
value = []
visit = set()
num = [0]*n
for i in range(m):
    i, v = map(int, input().split())
    value.append([i, v])
value.sort()
# print(value)
v = list()
for i in range(len(value)):
    if value[i][0] not in visit:
        v.append(value[i])
        visit.add(value[i][0])
# print(v)
for i in v:
    num[i[0]-1] = i[1]
need = "".join(map(str, num))
#print(need)
if len(str(int(need))) == n:
    print(need)
else:
    print(-1)