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

ans = 0
list = []
for n in range(N) :
    list.append(0)

for m in range(M) :
    keta, num = map(int, input().split())
    if int(num) > 0 :
        list[keta-1] = int(num)

for n in range(N-1, -1, -1) :
    ans = ans + (list[N-1-n] * 10**n)

if ans == 0 or N != len(str(ans)) :
    print(-1)
else :
    print(ans)

