n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = [str(0)]*n
for i in s:
    lis[int(i[0]) - 1] = str(i[-1])

lis = int("".join(lis))
if lis == 0 or len(str(lis)) != n:
    print(-1)
else:
    print(lis)