import sys
N, M = map(int, input().split())
s = [0]
c = [0]
num = [0] * (N + 1)
reg = [0] * (N + 1)
if N > 1:
  num[1] = 1

for i in range(M):
  a, b = map(int, input().split())
  if N > 1 and a == 1 and b == 0:
    print (-1)
    sys.exit()

  s.append(a)
  c.append(b)

for i in range(1, M + 1):
  if reg[s[i]] == 1 and num[s[i]] != c[i]:
    print (-1)
    sys.exit()
  num[s[i]] = c[i]
  reg[s[i]] = 1

result = ""
for i in range(1, M + 1):
  result += str(num[i])
print (result)

