n, m = map(int, input().split())
ans_list = [0] * n
list1 = []
for i in range(m):
    s, c = map(int, input().split())
    a = [s, c]
    list1.append(a)
list1.sort(reverse=True)
for i in range(m):
    s = list1[i][0]
    c = list1[i][1]
    if c == 0:
        ans_list[s - 1] = 0
    elif ans_list[s - 1] == 0 or ans_list[s - 1] > c:
        ans_list[s - 1] = c
    elif ans_list[s - 1] < c:
        pass
    else:
        print(-1)
        exit()
if ans_list[0] == 0:
    print(-1)
    exit()
ans = map(str, ans_list)
print("".join(ans))