N,M = map(int, input().split())
temp = [0] * N
for i in range(M):
    s,c = map(int, input().split())
    s = N-s
    if temp[s] == 0 or temp[s] == c:
        temp[s] = c[i]
    else:
        print(-1)
        exit()
ans = 0
for i in temp:
    ans += i*10**N
    N-=1
if ans<10**(N-1):
    print(-1)
    exit()
print(ans)