n, m = map(int, input().split())

ans_true = True

s_arr = []
c_arr = []

ans_dic = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}

for _ in range(m):
    s, c = map(int, input().split())
    s_arr.append(s)
    c_arr.append(c)


for i in range(len(s_arr)):
    if ans_dic[s_arr[i]] != 0:
        if ans_dic[s_arr[i]] != c_arr[i]:
            ans_true = False
    ans_dic[s_arr[i]] = c_arr[i]


ans = ''

if ans_dic[1] == 0:
    print('-1')
elif not ans_true:
    print('-1')
else:
    for num in range(n):
        ans += str(ans_dic[num+1])

print(ans)