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

x = [0] * N
y = [0] * N

for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    if y[s] != 0 and x[s] != c:
        ans = -1
    else:
        y[s] = 1
        x[s] = c

if N > 1 and x[0] == 0:
    ans = -1
else:
    ans = 0
    for i in range(N):
        ans += x[i] * (10**(N-i-1))

print(ans)
    