n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc_set = set(sc)
sc_list = list(sc_set)

used = [False] * n
for ele in sc_set:
    idx = ele[0] - 1
    if used[idx]:
        print(-1)
        exit()
    used[idx] = True

num = [None] * n
for i in range(len(sc_list)):
    num[sc_list[i][0] - 1] = sc_list[i][1]

if n == 1:
    print(num[0])

for i in range(10 ** (n - 1), 10 ** n):
    i = str(i)
    test = []
    for j in range(n):
        if num[j] == None:
            test.append(1)
        elif num[j] != None and num[j] == int(i[j]):
            test.append(1)
        else:
            test.append(0)
    if all(test):
        print(i)
        exit()

print(-1)