import numpy as np
N, M = map(int, input().split())

frag = True
A = np.zeros(N)
for i in range(N):
    A[i] = -1
for i in range(M):
    si,ci = map(int, input().split())
    if A[si-1] != -1 and A[si-1] != ci:
        frag = False
    elif si == 1 and ci == 0:
        frag = False
    else:
        A[si-1] = ci

ans = 0
for i in range(N):
    if A[N-i-1] == -1:
        A[N-i-1] = 0
    ans += A[N-i-1]*(10**i)
if ans < 10**(N-1):
    ans += 10**(N-1)
    
if frag:
    print(int(ans))
else:
    print(-1)