n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = [str(0)]*n
for i in s:
    if lis[int(i[0]) - 1] == "0" or lis[int(i[0]) - 1] == str(i[-1]):
        lis[int(i[0]) - 1] = str(i[-1])
    else:
        print(-1)
        exit()
lis = int("".join(lis))
if lis == 0:
    print(-1)
else:
    print(lis)