############### b #################

# def modify_flags(flags, temp):
#   num_idx = temp[0]*3+temp[1]
#   corr = {0:(1,6,7), 1:(2,6), 2:(3,6,8), 3:(1,5), 4:(2,5,7,8), 5:(3,5), 6:(1,4,8), 7:(2,4), 8:(3,4,7)}
#   for item in corr[num_idx]:
#     flags[item-1] += 1

# nums = {}
# for i in range(3):
#   x = [int(_) for _ in input().split(" ")]
#   for j in range(3):
#     nums[x[j]] = (i, j)

# flags = [0]*8
# N = int(input())
# for i in range(N):
#   temp = int(input())
#   if (temp not in nums.keys()):
#     continue
#   modify_flags(flags, nums[temp])

# rst = "No"
# for item in flags:
#   if (item == 3):
#     rst = "Yes"
#     break
# print(rst)

################# b end ################

################# C ###############
N, M = [int(x) for x in input().split(" ")]
digits = [-1] * N
flag = False
for i in range(M):
    s, c = [int(x) for x in input().split(" ")]
    if (digits[s-1] == -1 or digits[s-1] == c):
        digits[s-1] = c
    else:
        flag = True
        break
if (flag):
    print(-1)
elif (digits[0] == 0 or digits[0] == -1):
    print(-1)
else:
    for i in range(N):
        if (digits[i] != -1):
            print(digits[i], end="")
        else:
            print(0, end = "")
    print()
