N, M = list(map(int, input().split()))

numlist = [0] * N
for m in range(M):
    s, c = list(map(int, input().split()))
    if numlist[s - 1] == 0:
        numlist[s - 1] = c
    else:
        numlist[s - 1] = c if c <= numlist[s - 1] else numlist[s - 1]


if numlist[0] == 0:
    if N == 1:
        print(0)
    else:
        print(-1)
else:
    strlist = list(map(str, numlist))
    print(int(''.join(strlist)))
