# coding:utf-8

N, M = map(int, input().split(' '))
num_list = [0 for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split(' '))
    if num_list[s-1] == c:
        pass
    elif num_list[s-1] == 0:
        num_list[s-1] = c
    else:
        print(-1)
        exit(0)

flag = False
ans = ''
for num in num_list:
    if num != 0:
        flag = True
    if flag:
        ans += str(num)
print(ans if ans != '' else '-1')