n, m = [int(i) for i in input().split()]
sc = list(set([tuple(map(int, input().split())) for _ in range(m)]))

s = list('x'*n)
for i in range(len(sc)):
    if s[sc[i][0]-1] != 'x':
        print("-1")
        exit()
    s[sc[i][0]-1] = str(sc[i][1])

ans = int("".join(s).replace('x', '0'))
print(ans if len(str(ans)) == n and ans != 0 else -1)