n, m = map(int, input().split())
a = [list(input().split()) for _ in range(m)]
s = ["0"] * n
s[0] = "1"
if m >= 2:
    for i in range(0,m-1):
        for j in range(i+1, m):
            if a[i][0] == a[j][0] and a[i][1] != a[j][1]:
                print("-1")
                exit()
for i in range(m):
    s[int(a[i][0]) - 1] = str(a[i][1])
if n != 1 and s[0] == "0":
    print("-1")
    exit()
else:
    print("".join(s))