N,M = map(int,input().split())
SC = []

for i in range(M):
  sc = list(map(int,input().split()))
  SC.append(sc)

num = [0] * N

for i in range(M):
  s = SC[i][0]
  c = SC[i][1]
  if (num[s - 1] != 0 and num[s - 1] != c) or (s == 1 and c == 0):
    num = -1
    break
  else:
    num[s - 1] = SC[i][1]

if num == -1:
  print(-1)
else:
  ans = ""
  for i in range(M):
    if num[0] == 0:
      num[0] = 1
    ans += str(num[i])
  print(int(ans))