N, M = map(int, input().split())
my_list =[]

for i in range(M):
    array = list(map(int, input().strip().split()))
    my_list.append(array)

my_list = list(map(list, set(map(tuple, my_list))))


def main(my_list):
    num = [0] * N
    done =[0] * N
    ans = ""

    for l in my_list:
        if done[l[0]-1] == 1:
            return -1
        num[l[0]-1] = l[1]
        done[l[0]-1] = 1

    if num[0] == 0:
        if done[0] == 1:
            return -1
        else:
            num[0] = 1

    for i in range(len(num)):
        ans = ans + str(num[i])

    return int(ans)

print(main(my_list))