N, M = map(int, input().split(' '))
rst_ls = [0] * N
rst = ''
for i in range(M):
    ls = list(map(int, input().split(' ')))
    rst_ls[ls[0] - 1] = ls[1]
for i in rst_ls:
    rst += str(i)
rst = int(rst)
if N == len(str(rst)):
    print(rst)
else:
    print(-1)