N, M = map(int, input().split())
s_list = list()
c_list = list()
for _ in range(M):
    s, c = input().split()
    s_list.append(s)
    c_list.append(c)

out = '-1'
exists = True

num = 'd' * N
for index in range(len(s_list)):
    if num[int(s_list[index])-1] == 'd' or num[int(s_list[index])-1] == c_list[index]:
        # num[int(s_list[index])] = c_list[index]
        num_tmp = num[:int(s_list[index])-1]
        num_tmp += c_list[index] + num[int(s_list[index]):]
        num = num_tmp

    else:
        break

if exists:
    out = num.replace('d', '0')
    if out[0] == '0':
        out = '-1'

print(out)
