n, m = map(int, input().split())

listans = ["0"] * n

for i in range(m):
    s, c = map(str, input().split())
    if listans[int(s)-1] == "0":
        listans[int(s)-1] = str(int(c))
    elif listans[int(s)-1] != str(int(c)):
        print(-1)

if listans[0] == "0":
    print(-1)
else :
    print("".join(listans))