# -*- coding: utf-8 -*-
n, m = map(int, input().split())

sc_list = []

for i in range(m):
    sc_list.append(list(map(int, input().split())))

ans_list = [-1] * n

for item in sc_list:
    s = item[0]
    c = item[1]
    if ans_list[s-1] != -1 and ans_list[s-1] != c:
        print(-1)
        exit()
    else:
        ans_list[s-1] = c

if n > 1 and ans_list[0] == 0:
    print(-1)
    exit()

for i in range(len(ans_list)):
    if ans_list[i] == -1:
        ans_list[i] = 0

print("".join(list(map(str, ans_list))))
