N, M = map(int, input().split())
S = [0] * M
C = [0] * M
for i in range(M):
    S[i], C[i]= map(int, input().split())

A = 0

X = []
for j in range(M):
  if S[j] in X:
    X.append(S[j])
  else:
    A +=(10**((N-S[j])))*C[j]
    X.append(S[j])

str_B = list(str(A))

for k in range(M):
  if str_B[S[k]-1] != str(C[k]):
    A = -1

if A < 10**(N-1):
  A = -1

print(A)