n, m = map(int,input().split())
n_list = []

for i in range(m):
    s, c = map(int,input().split())
    n_list.append([s, c])

i = 0
flag = 0
i_string = ""
string_list = []

for i in range(10**n):
    list_i = list(str(i))
    list_i = [int(j) for j in list_i]
    if len(list_i) != n:
        continue
    for j in range(m):
        if list_i[n_list[j][0]-1] != n_list[j][1]:
            break
        elif j == m-1 and list_i[n_list[j][0]-1] == n_list[j][1]:
            print(i)
            flag = 1
            break
    if flag == 1:
        break

if flag == 0:
    print(-1)
