N, M = map(int, input().split())
data = {}
canMake = True
if M == 0:
  if N == 1:
    print(0)
  if N == 2:
    print(10)
  if N == 3:
    print(100)
  exit()

for _ in range(M):
  s, c = map(int, input().split())
  if s in data:
    if data[s] != c:
      canMake = False
  else:
    data[s] = c

keta = N
pad = min(data)
if min(data) == 1 and data[min(data)] == 0:
  canMake = False

if not canMake:
  print(-1)
  exit()

res = 0
for i in range(1, keta+1):
  if i in data:
    res += data[i]*10**(keta-i)
  elif i == 1:
    res += 10**(keta-i)

print(res)