import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(M)]
    answer = [0]*N
    for number in sc:
        if answer[number[0]-1] == 0 or answer[number[0]-1] > number[1]:
            answer[number[0]-1] = number[1]
    answer = "".join([str(s) for s in answer])
    print(answer) if answer[0] != "0" else print("-1")


if __name__ == '__main__':
    main()
