def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return

    digits = [d.pop() if d else 0 for d in dcon]

    if sum(digits) == 0 and n != 1:
        print(-1)
    else:
        print(''.join(map(str, digits)))


main()
