from collections import defaultdict
N, M = map(int, input().split())
constraint = defaultdict(set)
for _ in range(M):
    s, c = map(int, input().split())
    constraint[s].add(c)

for k, v in constraint.items():
    if len(v) > 1:
        print(-1)
        exit()

for i in range(1, 1001):
    i = str(i)
    if len(i) < N:
        continue
    flag = True
    for k, v in constraint.items():
        if i[k-1] != str(list(v)[0]):
            flag = False
    if flag:
        print(i)
        exit()
print(-1)
