N, M = map(int, input().split())
A = [0] * N
B = [0] * N
T = 1
ans = 0
for i in range(M):
  s_i , c_i = map(int, input().split())
  if B[s_i - 1] == 0:
    A[s_i - 1] = c_i
    B[s_i - 1] = 1
  else:
    if A[s_i - 1] != c_i:
      T = 0
for i in range(N):
  y = A[N - i - 1]
  y = int(y)
  ans = ans + y * 10 ** i
if T == 0:
  ans = -1
elif A[0] == 0 and N !=1 :
  ans = -1
print(ans)